Bruno Marques@Allakazan

15 March 2020

Running your NodeJs app as a service

How to use the systemd to deploy your NodeJs applications

nodejs deploy unix systemd

You spent some time making your node app and now you need to deploy locally, or on a server. How to keep track of your app status ?

The best known solution is the systemd, the UNIX default service manager.

Node Application:

In this app we will be using express, so if you want follow the node app, please run:

npm install express --save

Let’s create our node app first:

var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Node Js App!');
});

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});

Now just run your node app and open the url: localhost:3000 in your browser.

Unix Service:

First create a file named your-node-app.service inside /etc/systemd/system/, then copy the text below to your file:

Run systemctl daemon-reload to reload the service files. Then use systemctl start your-node-app

You can run too systemctl status your-node-app to check your application status.

And is done, your app is running as a unix service.