Skip to content

Instantly share code, notes, and snippets.

@mitchallen
Last active March 13, 2023 02:41
Show Gist options
  • Save mitchallen/17607c379f68d1e1f97ee3c155216959 to your computer and use it in GitHub Desktop.
Save mitchallen/17607c379f68d1e1f97ee3c155216959 to your computer and use it in GitHub Desktop.
A very simple Node.js Web Server
/**
* Author: Mitch Allen
* https://scriptable.com
* https://mitchallen.com
*/
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('Hello World!');
});
const server = app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});
process.on('SIGINT', () => {
console.debug('\nSIGINT signal received: closing HTTP server')
server.close(() => {
console.debug('HTTP server closed')
})
process.exit();
})
process.on('SIGTERM', () => {
console.debug('\nSIGTERM signal received: closing HTTP server')
server.close(() => {
console.debug('HTTP server closed')
})
process.exit();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment