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:

  1. Create an instance.
  2. Update & upgrade the system.
  3. 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.
  4. Install node process manager. I prefer pm2. There are other options, but pm2 just does its job and is suitable for microservices architecture. The main purpose of pm2 in my case is to keep node application running and autostart my application even if something goes wrong.
  5. Add a DNS record that would point some domain to the servers IP.
  6. 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.
  7. Clone some git repository.
  8. Run pm2 start index.js from the project folder.
  9. Configure caddy through a Caddy file and start it.