How to run a nodejs app as a systemd service

I usually run multiple Web apps on one server. And I really dislike having to restart them all when I restart the server.

So I decided to take a little time and finally learn systemd.

After some trial, error and a few tutorials I had the configurations I needed.

Configurations for some popular services


Ghost Blog
[Service]
ExecStart=/home/sysadmin/.n/n/versions/node/4.2.6/bin/node index.js  
WorkingDirectory=/home/sysadmin/blogfolder/  
Restart=always  
StandardOutput=syslog  
StandardError=syslog  
User=sysadmin  
Group=sysadmin  
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target  

Rocket.Chat
[Service]
ExecStart=/home/sysadmin/.n/n/versions/node/0.10.41/bin/node main.js  
WorkingDirectory=/home/sysadmin/Rocket.Chat  
Restart=always  
StandardOutput=syslog  
StandardError=syslog  
User=sysadmin  
Group=sysadmin  
Environment=ROOT_URL=[https://yourdomain.com]  
Environment=MONGO_URL=mongodb://localhost:27017/[dbname]  
Environment=PORT=3000

[Install]
WantedBy=multi-user.target  

Start a Docker Container
[Unit]
Requires=docker.service  
After=docker.service

[Service]
Restart=always  
ExecStart=/usr/bin/docker start -a [containerName]  
ExecStop=/usr/bin/docker stop [containerName]

[Install]
WantedBy=multi-user.target