Last active
March 13, 2023 02:41
-
-
Save mitchallen/17607c379f68d1e1f97ee3c155216959 to your computer and use it in GitHub Desktop.
A very simple Node.js Web Server
This file contains hidden or 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
| /** | |
| * 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