Node was designed with server-side web development in mind and has a lot of thoughtful functionality towards that end. At its most simple, however, it provides the ability to run JavaScript programs on our own computers instead of just in the browser’s console or embedded in HTML.
In this lesson, we’ll explore some of the functionality and properties specific to the Node environment, but first, let’s see how we run a program.
We’ll need to create a file with a .js
extension. We’ll call ours myProgram.js. Next, we’ll open that file with a text editor and add our code:
// Inside myProgram.js console.log('Hello World');
Our code is complete! Now, we want to execute it. We’ll open our terminal and navigate to the directory that contains myProgram.js. Finally, we’ll type the command node myProgram.js
into our terminal.
$ node myProgram.js
The results of our program will print to the terminal.
Hello World
Let’s write a program and run it in Node.
Instructions
We’ve written a silly sentence JavaScript program in the app.js file. There are a number of variables assigned the string '____'
. Replace each of them with words of the designated type:
let adjective = 'silly';
When you’re ready to move on to the next step, click the “Check Work” button.
Let’s run the program in the terminal so we can see its output. Type node app.js
in the terminal and press enter or return, and then press “Check Work”. You should see the output of the program in the terminal!