Logo von node.js

Node.js is a JavaScript runtime environment popular with developers for network applications that works event-based – not unlike JavaScript run in a browser. Node.js, on the other hand, runs on the server – like PHP, for example – and also provides a web server for this purpose. Unlike PHP, which uses a separate CPU thread for each request that is blocked until the request is answered, Node.js works asynchronously (“non-blocking I/O”) via an “event loop” in a single thread and thus uses server resources more sparingly and efficiently – which is why PHP has also received ansynchronous extensions in the meantime.

In addition, Node.js comes with the package manager npm, which in turn provides access to a veritable universe of JavaScript packages, the npm registry, that can be used to solve every conceivable task. Sounds like a perfect solution for JavaScript programmers.

But at the end of 2014, storm clouds were gathering in the sky when leading developers, dissatisfied with the Node.js sponsor Joyent, created a spin-off called io.js. Since version 4, however, the two projects have been reunited, and the development of Node.js was placed in the hands of a foundation.

The “all you can eat” mentality, with which developers relay on the bubbling npm registry also holds dangers, however. There have been isolated cases of compromised packages, and in the end of 2021 are vulnerability was patched that seemed to be undetected for many years. In early 2022 the developer of the popular faker.js and colors.js libraries sabotaged his own packages to protest against large companies using his code without paying for it.

Despite everything: Node,js and its registry, now operated by Github and thus Microsoft, enjoy so much popularity in the JavaScript world, that even applications that do not need Node at all are now installed on top of it. Popular examples include frontend frameworks like ReactJS.

Release schedule

New versions of Node.js are released every six months and are then considered current for six months. Even version numbers also receive long-term support (LTS) of 30 months, for a total lifespan of three years. Ubuntu 22.04 still shipped the aged LTS version 12 when it was released, while Node.js’ homepage already lists version 16 as the current LTS version.

How to install node.js on Ubuntu

Nodejs can be quickly obtained from the Ubuntu package sources:

sudo apt install nodejs

This installs a maintained LTS version, but not necessary the latest, and without support directly from Ubuntu, because the package is only in the Universe repository. There are three ways to get a current version at any time:

  • Enter the Nodesource repository as an additional package source and conveniently install and update node.js via apt.
  • Use the Node Version Manager (nvm), a bash script, to download one or more Node versions and run them in parallel.
  • Manually download and install the desired version directly from the Node.js download page.

The npm documentation recommends using nvm over an installer, because otherwise npm is installed in a local context, so that errors can occur when packages are to be executed globally. Nevertheless, here is an example of how to set up the nodesource repository using a script provided by them for LTS version 16:

curl -sL | sudo -E bash -
sudo apt install nodejs npm