Skip to content

Instantly share code, notes, and snippets.

@MylesBorins
Last active January 29, 2020 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MylesBorins/a1df049260c1db8568bf1a9ced74a8bd to your computer and use it in GitHub Desktop.
Save MylesBorins/a1df049260c1db8568bf1a9ced74a8bd to your computer and use it in GitHub Desktop.
lol whoops
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();
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