Skip to content

Instantly share code, notes, and snippets.

@apwan
Created September 9, 2018 09:54
Show Gist options
  • Save apwan/c45a075d79d410bacab4874915b486c3 to your computer and use it in GitHub Desktop.
Save apwan/c45a075d79d410bacab4874915b486c3 to your computer and use it in GitHub Desktop.
Use start-stop-daemon to launch/exit node app.
#!/usr/bin/env node
//app.js
var http = require('http');
server = http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<h1>Node.js</h1>');
res.end('<p>Hello World</p>');
}).listen(process.env.PORT||4321);
console.log("HTTP server is listening at port "+server.address().port);
#!/usr/bin/env bash
start-stop-daemon --start --quiet --pidfile $1 -m --exec /usr/bin/env -- node app.js > $2 &
#/usr/bin/env bash
start-stop-daemon --stop -p $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment