Skip to content

Instantly share code, notes, and snippets.

@hex128
Last active July 30, 2016 17:26
Show Gist options
  • Save hex128/40dbf35c081d86e4670c to your computer and use it in GitHub Desktop.
Save hex128/40dbf35c081d86e4670c to your computer and use it in GitHub Desktop.
Node.JS server with SystemD socket activation
[Service]
ExecStart=/usr/bin/node /var/www/server.js
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodejs
User=www-data
Group=www-data
[Socket]
ListenStream=/var/run/nodejs.sock
[Install]
WantedBy=sockets.target
require('systemd');
require('autoquit');
var http = require('http'),
express = require('express'),
app = express();
app.get('/', function (req, res) {
res.contentType('text/plain');
res.send('Hello Express');
});
app.use(function(req, res, next) {
res.status = 404;
res.json({status: res.status});
});
app.use(function(err, req, res, next) {
var status = err.status || err.statusCode || 500;
res.status = status;
res.json({status: res.status});
});
app.listen('systemd').autoQuit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment