Go live on linux Server With Node JS App

I have described the deployment in steps for a new server which does not have any software installed, but if you have those software installed, just skip those steps and move on to next.

Installations

1. Download nvm. NVM is a node version manager and in order to install Node and npm, first nvm is to be installed using following commands.

/curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

. ~/.nvm/nvm.sh

2. Next install node and npm, the version should be the version as your application, if version is not given, the latest version will get installed.

nvm install <<version>>

3. For getting the code from any of your git repositories, install git package, skip this step if the code can be copied using any other way like ftp, winscp etc.

sudo dnf install git

4. Install pm2 server, pm2 is a package which ensures api running even system crashes, application crashes and such, it automatically restarts the app again.

npm install -g pm2

Deployment

5. Copy the code to server directory wherever you want.

git clone <<github or any other git repo url>>

6. Run the app using pm2.

pm2 start app.js 

Ensure that the port eg. 3000 on which the node js application is listening is open on the server.

Now you can check the api end points using postman or browser. Replace localhost with ip of the server in all your end points.


Similar Articles