Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.