If you’re like me and you want your environment to be more serverless than Serverless and more impervious to extraneous expense, then maybe your Node.js app is on a Digital Ocean droplet as a systemd service.
- I installed pathman on the droplet to manage my path. It’s easier to use than editing your profile. It also gives you a path to source for the remote SSH command works without tinkering. If you’ve tried to write a local bash script that should run remotely, you’ll know what I mean.
- I installed serviceman to create the systemd service on the droplet. It’s way easier than editing a systemd config manually. It just works.
This deployment starts by using rsync to sparse copy the relevant project files into place on the server. Unnecessary files like
.DS_Store are excluded, as well as
node_modules which is different where the development environment is different than production. The
.git directory is also excluded.
Run Remote Commands
Once the files are in place, we install our dependencies and restart the service.
This is the simplest Node.js deployment script.
#!/usr/bin/env bash rsync -rDv . myawesomeapp.com:/srv/ \ --exclude '.DS_Store' \ --exclude '.git/' \ --exclude 'node_modules/' ssh myawesomeapp.com <<EOF [ -e ".config/envman/PATH.env" ] && source .config/envman/PATH.env cd /srv/ npm ci --production sudo systemctl restart app EOF