Deploy node.js express micro service to linux server and go live in 10 minutes
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.
I am using aws Amazon Linux 2023 for demo, but the deployment will work for any linux server.
Installations
- 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.
Like it!! Buy me a coffee
Subscribe to my newsletter
Read articles from Samarth Srivastava directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by