Skip to main content

Node.js

Node.js is a lightweight and efficient JavaScript runtime. It makes it possible to create high-performance server applications and tools. Node.js is built on the V8 JavaScript engine and written in C++.

Initially, Node.js was created as a server environment for applications, but developers began to use it to create tools for automating local tasks. As a result, the new ecosystem that emerged around Node.js transformed the front-end development process.

Installation

To install the latest stable version, go to the official page, download the LTS installer and follow the instructions. You will find installers for all popular operating systems – Windows, MacOS and Linux.

Note

Windows users need to check all the boxes to install all additional tools except Chocolatey. This will install Python and all sorts of utilities and compilers.

After installation, the node command will be available in the terminal. To make sure that the installation has been successful, check the version by running the node command with the version flag in the console.

node --version

JavaScript outside the browser

Node.js allows JavaScript code to run outside the browser. Open any terminal and execute the node command; it will activate REPL (read-eval-print-loop), an interactive JS code runtime. Let's display something in the console.

nodejs log
Note

To exit REPL, press Ctrl + C on Windows or Control + C on MacOS.

Now let's create a folder, node-tut, and a file, index.js, with the code written in REPL. To start, you need to open the terminal and go to the node-tut folder, which contains index.js.

// index.js
const message = "NodeJS in amazing!";
console.log(message);

Now, in the console, run the file using the node index.js command and get the same result, i.e. you will see the line in the terminal.

file execution by nodejs

The upshot of Node.js: the ability to execute JavaScript outside the browser. With this you can code complete applications, such as back-end or browser-independent utilities.