Skip to content

Instantly share code, notes, and snippets.

@dapize
Last active January 7, 2023 18:49
Show Gist options
  • Save dapize/49b400d5dd281459d55f248be18a8fb9 to your computer and use it in GitHub Desktop.
Save dapize/49b400d5dd281459d55f248be18a8fb9 to your computer and use it in GitHub Desktop.
Create a service for a node express app
# first we have to create a file in this target:
sudo nano /etc/systemd/system/hereTheNameOfTheService.service
# inside that file we have to paste this:
[Unit]
Description=A Description of my service
After=network.target
[Service]
Environment="HTTP_PORT=8000"
Environment="HTTPS_PORT=4430"
Type=simple
User=username
Group=username
ExecStart=/usr/bin/node /home/username/app/index.js
ExecStop=kill -9 $(ps aux | grep '/usr/bin/node /home/username/app/index.js' | awk '{print $2}')
Restart=on-failure
[Install]
WantedBy=multi-user.target
# after that we have to set 'enabled' the service:
usudo systemctl enable hereTheNameOfTheService.service
# and finnally, we have to start the service
sudo systemctl start hereTheNameOfTheService.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment