Created
August 24, 2020 09:03
-
-
Save mxschmitt/d4f2c04a4e1267158eaceb84a8f06ae1 to your computer and use it in GitHub Desktop.
Node.js web server with top-level-await and async for loop
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
// Run it with: node --harmony-top-level-await test.mjs | |
import { createServer } from 'http' | |
import { on } from 'events' | |
const PORT = 3000 | |
const reqs = on(createServer().listen(PORT), "request") | |
console.log(`Listening on port ${PORT}`) | |
for await (const [req, res] of reqs) | |
res.end(`User-Agent: ${req.headers["user-agent"]}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment