This blog post is part of the series “Web development for beginners” – which teaches people who have never programmed how to create web apps with JavaScript.
To download the projects, go to the GitHub repository learning-web-dev-code and follow the instructions there.
I’m interested in feedback! If there is something you don’t understand, please write a comment at the end of this page.
Node.js is a program that lets us run JavaScript code outside browsers – which we can use for a variety of things.
What is Node.js? It’s a program that uses a JavaScript engine to run code in local files (stored in the file system of your computer). That gives us the following useful features:
A JavaScript platform is an application that has a JavaScript engine and lets us run JavaScript code. Browsers and Node.js are both JavaScript platforms.
Please download Node.js at the Node.js website and install it. For beginners, it’s probably easiest to use an installer application. You can download it on the official download page, a bit further down: “Or get a prebuilt Node.js”.
You should now be able to start Node.js by typing the following command in a shell:
node
If we start Node.js like this (without any shell arguments) then we are in a Node.js console that works much like a browser console – e.g. this is one interaction with it (try it out yourself!):
> 16 * 16
256
The Node.js console is also called a REPL, which stands for read-eval-print loop:
16 * 16)256)hello-nodejs.js We are now ready to run JavaScript code via Node.js. This is what’s in the file hello-nodejs.js:
console.log('Node.js says “hello”!');
We can run it via the following shell commands:
cd learning-web-dev-code/projects/
node hello-nodejs.js
As a result, we see the following output in the terminal:
Node.js says “hello”!
We have just seen and run our first Node.js app!