documentation/Examples/Debian/Install Node.js.md

54 lines
1.4 KiB
Markdown

###### About
<https://nodejs.org/en>
###### Procedure
1. Sign in as root user
2. Run `apt install nodejs`
!!! info "Note"
This command may install an older version of Node.
3. Run `node --version` to verify the installed version of Node.js
4. Run `apt install npm` to install the Node package manager
5. Run `npm install -g n` to *globally* install the `n` Node version manager
6. Run `n latest` to fetch and install the latest version of Node.js
###### Optional
1. 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:
```sh title="/root/myapp/myapp.sh"
#!/bin/bash
cd /root/myapp
source ./venv/bin/activate
python3 -u myapp.py
```
1. Run `cd /root/myapp`
2. Run `pm2 start myapp.sh` to daemonize `myapp.sh` with PM2
3. Run `pm2 startup` to enable running PM2 at system startup
4. 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, run `pm2 log myapp`.
###### About PM2
<https://pm2.keymetrics.io/>