This video is available to students only

How to Run a JavaScript File with Node.js

In this lesson, we'll use Node to run a simple JavaScript file on the server.

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

Running JavaScript with Node

We have our Visual Studio Code Editor and our terminal available to us in our workspace.

To begin, we'll start with an empty folder labeled tinyhouse_v1/ in our editor workspace.

tinyhouse_v1/

tinyhouse_v1/ would be the directory where we build the app for the first part of our course. To get things started we're going to create a subfolder called server within the tinyhouse_v1/ project that would host the server portion of our app. We'll also go ahead and have an index.js file be created within this server subfolder.

tinyhouse_v1/
  server/
    index.js

The node command

For our very first attempt, we're going to see how we could use node to run some JavaScript code and the first code we're going to write is a simple console.log message.

We're going to attempt to log something into our terminal console and the first thing we're going to look to log is a simple string that says 'hello world'.

server/index.js
console.log('hello world');

Next, we're going to create two constant variables. We're going to create a variable called one and another called two and assign them numerical values according to the variable name.

This lesson preview is part of the The newline Guide to Building Your First GraphQL Server with Node and TypeScript course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

Unlock This Course

Get unlimited access to The newline Guide to Building Your First GraphQL Server with Node and TypeScript, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course The newline Guide to Building Your First GraphQL Server with Node and TypeScript