Skip to content

Instantly share code, notes, and snippets.

@tomfun
Created April 6, 2017 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfun/f821e284fdaad365922b921861ef74bc to your computer and use it in GitHub Desktop.
Save tomfun/f821e284fdaad365922b921861ef74bc to your computer and use it in GitHub Desktop.
tested in AWS in Docker
'use strict';
/*
If you are using docker, you must change CMD from
CMD node www-server.js
to
CMD ["node", "www-server.js"]
*/
require('http-shutdown').extend()
var http = require('http');
var server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
setInterval(function() {
res.end(' World\n');
},10000);
console.log("Hello");
})
.withShutdown()
.listen(4000, '0.0.0.0');
console.log('server started');
process.on('SIGTERM', () => {
console.log('on: SIGTERM down the server');
server.shutdown(function() {
console.log('Everything is cleanly shutdown.');
process.exit(0);
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment