Created
November 22, 2022 23:17
-
-
Save bisgardo/b07b804f401f65804c65cc376f7e7b9e to your computer and use it in GitHub Desktop.
Tiny Node.js server for serving the latest line entered on stdin.
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
const port = process.env.PORT || 4258; | |
const hostname = '0.0.0.0'; | |
let content = null; | |
require('http') | |
.createServer((req, res) => res.end(content)) | |
.listen(port, hostname, () => console.log(`Listening on http://${hostname}:${port}`)); | |
require('readline') | |
.createInterface({input: process.stdin, output: process.stdout, terminal: false}) | |
.on('line', line => { | |
line = line.trim(); | |
if (line) content = line; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment