Created
October 31, 2014 13:31
-
-
Save gabrysiak/8c1d626b3a6a4ee36ec9 to your computer and use it in GitHub Desktop.
NodeJS basic server and startup script to run application as service
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
// npm init | |
// install --save compression connect http serve-static | |
// vim server.js | |
var connect = require('connect'); | |
var http = require('http'); | |
var app = connect(); | |
var compression = require('compression') | |
app.use(compression()) | |
var static = require('serve-static'); | |
app.use(static(__dirname + "/httpdocs")); | |
http.createServer(app).listen(process.env.PORT || 80); | |
/** create a file called node.server.conf in /etc/init/ **/ | |
description "node.js server" | |
author "Your name" | |
# used to be: start on startup | |
# until we found some mounts weren't ready yet while booting: | |
start on started mountall | |
stop on shutdown | |
# Automatically Respawn: | |
respawn | |
respawn limit 99 5 | |
script | |
# Not sure why $HOME is needed, but we found that it is: | |
export HOME="/root" | |
exec /usr/local/bin/node /var/www/server.js >> /var/log/node.log 2>&1 | |
end script | |
post-start script | |
// start node-server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment