Skip to content

Instantly share code, notes, and snippets.

@bisgardo
Created November 22, 2022 23:17
Show Gist options
  • Save bisgardo/b07b804f401f65804c65cc376f7e7b9e to your computer and use it in GitHub Desktop.
Save bisgardo/b07b804f401f65804c65cc376f7e7b9e to your computer and use it in GitHub Desktop.
Tiny Node.js server for serving the latest line entered on stdin.
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