Skip to content

Instantly share code, notes, and snippets.

@dylanjha
Created June 1, 2017 03:03
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 dylanjha/9417882e9bb8ed6fd72b1a7ee9018c2b to your computer and use it in GitHub Desktop.
Save dylanjha/9417882e9bb8ed6fd72b1a7ee9018c2b to your computer and use it in GitHub Desktop.
Testing out express process exit behavior
'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