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.
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'
.
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 page is a preview of The newline Guide to Building Your First GraphQL Server with Node and TypeScript