Last active
January 29, 2020 07:04
-
-
Save MylesBorins/a1df049260c1db8568bf1a9ced74a8bd to your computer and use it in GitHub Desktop.
lol whoops
This file contains 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 {createServer} = require('http'); | |
const {once} = require('events'); | |
const hostname = '127.0.0.1'; | |
const port = 3000; | |
const server = createServer((req, res) => { | |
res.statusCode = 200; | |
res.setHeader('Content-Type', 'text/plain'); | |
res.end('Hello World'); | |
}); | |
async function main() { | |
server.listen(port, hostname); | |
await once(server, 'listening'); | |
console.log(`Server running at http://${hostname}:${port}/`); | |
} | |
main(); |
This file contains 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 {createServer} = require('http'); | |
const {promisify} = require('util'); | |
const hostname = '127.0.0.1'; | |
const port = 3000; | |
const server = createServer((req, res) => { | |
res.statusCode = 200; | |
res.setHeader('Content-Type', 'text/plain'); | |
res.end('Hello World'); | |
}); | |
const serverOn = promisify(server.on).bind(server); | |
async function main() { | |
server.listen(port, hostname); | |
await server.on('listening'); | |
console.log(`Server running at http://${hostname}:${port}/`); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment