Skip to content

Start Production

Video Lecture

Start Production Start Production

Description

Navigate into the folder on your new server that contains the package.json

cd /var/www/socketio-example

Now, install the dependencies from the package.json by using the command,

npm install --omit=dev

Now, you can start the server script.

npm start

Open a browser and visit http://[your ip address]:3000

Go back into SSH and press Ctrl-C to stop the server.

We will now start it using the PM2 process manager for Node.JS.

It will start our script as a background process so that it doesn't block the terminal, and it remains running if we close Putty or exit the SSH session.

PM2 will also try to restart our application in case it ever crashes.

Install PM2 globally.

npm install pm2 -g

CD into the folder where the package.json was saved.

cd /var/www/socketio-example

Now we can start our server using PM2.

pm2 start npm -- start

To check the status,

pm2 status

To check the server output,

pm2 logs

To stop a PM2 process,

pm2 stop 0

To start a PM2 process,

pm2 start 0

To rename a PM2 process,

pm2 restart 0 ---name socketio-example