Created
June 1, 2017 03:03
-
-
Save dylanjha/9417882e9bb8ed6fd72b1a7ee9018c2b to your computer and use it in GitHub Desktop.
Testing out express process exit behavior
This file contains 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
'use strict' | |
const express = require('express') | |
const app = express() | |
const http = require('http') | |
const server = http.createServer(app).listen(9000, () => { | |
console.log('debug', 'express started process:', process.pid) | |
app.get('/test-1', (req, res, next) => { | |
console.log('debug', 'start: 1') | |
setTimeout(() => { | |
console.log('debug', 'end: 1') | |
res.status(200).send('ok') | |
}, 4000) | |
}) | |
app.get('/test-2', (req, res, next) => { | |
console.log('debug', 'start: 2') | |
setTimeout(() => { | |
console.log('debug', 'end: 2') | |
}, 4000) | |
res.status(200).send('ok') | |
}) | |
}) | |
process.on('SIGTERM', () => { | |
console.log('debug', 'graceful') | |
server.close(() => { | |
console.log('debug', 'server closed') | |
process.exit(0) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment