Node.js

Introduction

Warning

Node.js scripts belong in your home, not in your docroot.

Node.js is a server-side JavaScript interpreter. Node.js is commonly used to develop server-based applications, i.e. the scripts bind to a network port.


Versions

Release types

We provide different releases and apply security updates on a regular basis. Currently, these Node.js versions are available: 12, 14, and 16

Standard version

If you don’t select a certain version, our default will be used. We decided to default to version 16, which is considered to be stable by the developers.

Show available versions

Use uberspace tools version list node to show all selectable versions:

[isabell@stardust ~]$ uberspace tools version list node
- 12
- 14
- 16
[isabell@stardust ~]$

Change version

You can select the Node.js version with uberspace tools version use node <version>. You can choose between release branches:

[isabell@stardust ~]$ uberspace tools version use node 14
Selected node version 14
The new configuration is adapted immediately. Patch updates will be applied automatically.
[isabell@stardust ~]$

Selected version

You can check the selected version by executing uberspace tools version show node on the command line:

[isabell@stardust ~]$ uberspace tools version show node
Using 'node' version: '16'
[isabell@stardust ~]$

Update policy

We update all versions on a regular basis. Once the support ends, the branch reaches its end of life (EOL), is no longer supported and will be removed from our servers. Even-numbered versions are long-term support (LTS) versions.

Branch

State

Supported Until

12

Maintenance

April 2022

14

Active

April 2024

16

Current

April 2024


Run node application in the background

To run your node application in the background we use supervisord.

Assuming your application files are located in the sub folder ~/my-node-app of your home directory. Then place a daemon service file called my-daemon.ini in /home/isabell/bin/my-daemon:

[program:my-daemon]
directory=/home/isabell/my-node-app
command=npm run start
autostart=true
autorestart=true
environment=NODE_ENV=production

Afterwards, ask supervisord to look for the new my-daemon.ini file:

[isabell@stardust ~]$ supervisorctl reread
my-daemon: available

And then start your daemon:

[isabell@stardust ~]$ supervisorctl update
my-daemon: added process group

Start / Stop node daemon

To start a non-running service or stop a running one, use supervisorctl start my-daemon and supervisorctl stop my-daemon. To restart a service, you can also use supervisorctl restart my-daemon.

[isabell@stardust ~]$ supervisorctl start my-daemon
my-daemon: started
[isabell@stardust ~]$ supervisorctl stop my-daemon
my-daemon: stopped
[isabell@stardust ~]$ supervisorctl restart my-daemon
my-daemon: stopped
my-daemon: started

Connection to webserver

In order to make your application accessable from the outside, you need to connect it to the webserver, using a web backend.

Please note that your application must listen on the IP 0.0.0.0. You can choose any port between 1024 and 65535.


Available package managers

npm

npm, or the node package manager, is used to install and manage additional packages. We have preconfigured npm to install packages to your home when using the global (-g) option.

yarn

yarn is an alternative node package manager. It is used to install and manage additional packages of your node application.

npx

You can use npx to quickly execute and test any npm package without the need to create a nodejs project around it. Check out nodejs.dev to learn more.