1.4 KiB
About
Procedure
-
Sign in as root user
-
Run
apt install nodejs
!!! info "Note"
This command may install an older version of Node.
-
Run
node --version
to verify the installed version of Node.js -
Run
apt install npm
to install the Node package manager -
Run
npm install -g n
to globally install then
Node version manager -
Run
n latest
to fetch and install the latest version of Node.js
Optional
-
Install the PM2 daemon process manager globally via:
npm install -g pm2
This package allows daemonizing Node projects or shell scripts without the need to learn System V run levels, "init," or systemd services. For example, if we have a shell script that spawns a Java or Python-written server, you can use PM2 to host it:
#!/bin/bash cd /root/myapp source ./venv/bin/activate python3 -u myapp.py
-
Run
cd /root/myapp
-
Run
pm2 start myapp.sh
to daemonizemyapp.sh
with PM2 -
Run
pm2 startup
to enable running PM2 at system startup -
Run
pm2 save
to save the current process list
To view a list of all daemonized processes, run
pm2 list
. If your application crashes, PM2 will automatically restart your process, but may fail if the application is crashing in rapid succession. To view why, runpm2 log myapp
. -