How to deploy node js project on Centos

Install correct version of Node
The problem is, node js have not supported yum anymore so you need to use another repository
install package centos-release-scl available in CentOS repository:

sudo yum install centos-release-scl-rh

Install the collection:

sudo yum install rh-nodejs12

Start using software collections:

scl enable rh-nodejs12 bash

Now check version of node

node -v

It should say latest version of node
Deploy a project
1. Put your source to server
2. Install pm2 to keep your node app running after quit ssh console

npm install pm2 -g

3. Run your application with pm2
For example with nest app
3.1 build your app first

npm run build
3.2 Run 
pm2 start dist/main.js

Output will like this
[root@centos-s-1vcpu-1gb-sgp1-01 public_html]# pm2 start dist/main.js
[PM2] Starting /home/your_web_root/public_html/dist/main.js in fork_mode (1 instance)
[PM2] Done.
┌─────┬─────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼─────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ main │ default │ 0.0.1 │ fork │ 13828 │ 0s │ 0 │ online │ 0% │ 12.8mb │ root │ disabled │

Leave a Reply

Your email address will not be published. Required fields are marked *