Node

Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. By installing Node on you computer, you can use source files written in Javascript and run them as programs with Node.

As with the other tools, don’t worry about the specifics of Node and programming in Javascript; you’ll only need to follow instructions to use it.

Make sure you have a recent version of Node installed on your computer. Check the website for the current versions. It is advised to use an LTS (Long Term Support) version of Node.

Check the Installation

Run the following command in your terminal application to make sure your version is up to date.

$ node -v

The output should show the version of Node as shown below. If the program cannot be found, follow the instructions on the website to (re-)install Node on your computer.

Example output of node -v
v19.1.0

With Node installed, create a new file in a temporary directory to test Node out. Copy the following content into the file and save it as server.js.

Example Node.js Program
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

This program (which was taken from the Node.js getting started guide) runs a web server, that you can interact with. You can now start the program from your terminal application, by changing to the directory of the server.js file and running it with the node command.

Running the server.js Program
  $ node server.js

The output should be:

Output of the server.js program
Server running at http://127.0.0.1:3000/

The server is now running until you press Ctrl+c in your terminal application. Start another instance of your terminal application and use curl to test the server.

Testing the server
  $ curl http://127.0.0.1:3000/

The response from the server should read Hello World.

Node is now working fine!