Last active
July 30, 2016 17:26
-
-
Save hex128/40dbf35c081d86e4670c to your computer and use it in GitHub Desktop.
Node.JS server with SystemD socket activation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Service] | |
ExecStart=/usr/bin/node /var/www/server.js | |
StandardOutput=syslog | |
StandardError=syslog | |
SyslogIdentifier=nodejs | |
User=www-data | |
Group=www-data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Socket] | |
ListenStream=/var/run/nodejs.sock | |
[Install] | |
WantedBy=sockets.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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