Node.js
Cierre agraciado
Buscar..
Cierre agraciado - SIGTERM
Al usar server.close () y process.exit () , podemos detectar la excepción del servidor y hacer un cierre correcto.
var http = require('http');
var server = http.createServer(function (req, res) {
setTimeout(function () { //simulate a long request
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}, 4000);
}).listen(9090, function (err) {
console.log('listening http://localhost:9090/');
console.log('pid is ' + process.pid);
});
process.on('SIGTERM', function () {
server.close(function () {
process.exit(0);
});
});
Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow