I've deployed a lot of services and it's time to write an article about it.
Deploying a Node.js application require this steps:
- Create an instance.
- 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, butpm2
just does its job and is suitable for microservices architecture. The main purpose ofpm2
in 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.
- Clone some git repository.
- Run
pm2 start index.js
from the project folder. - Configure caddy through a Caddy file and start it.