I've deployed a lot of services and I want to share a list of actions that I usually perform. No clouds, just oldschool vps.
Deploying a Node.js application require this steps:
- Create an instance of vps.
- Update & upgrade the system.
- Install node version manager (
nvm) for simplify installation of any node version. Today we can just use the standard version, but I still like to be able to switch node version in a seconds. - Install node process manager. I prefer
pm2. There are other options, butpm2just does its job and is suitable for microservices architecture. The main purpose ofpm2in my case is to keep node application running and autostart my application even if something goes wrong. - Add a DNS record that would point some domain to the servers IP.
- Caddy server. Fast and simple configurable server. It automatically gets SSL certificate from Let's Encrypt. It proxies our node service from any port and serve it as https. There is a way to set up a websocket configuration.
- Clone your git repository. Go into that folder and resolve deps.
- Run
pm2 startupto configure your server in a way that it would automatically launch pm2 if reboot happens at some point. - Run
pm2 start index.jsfrom the project folder. - Configure caddy through a Caddy file and start it.