0.0.0 • Published 1 year ago
@kikobeats/async-listen v0.0.0
async-listen
The server.listen in Node.js is based on an event emitter, meaning the event should be waited before interacting with the server.
async-listen is the missing interface for consuming server.listen
as promise.
Install
$ npm install async-listen --save
Usage
const listen = require('async-listen')
const { createServer } = require('http')
const server = createServer((req, res) => {
res.end('hello world!')
})
const url = await listen(server)
console.log(`Listening at ${url.toString()}`)
After passing server
as first argument, the rest of parameters are the same than server.listen
:
/* IPv6 with random port (default) */
await listen(server)
/* IPv6 with port */
await listen(server, 3001)
/* IPv4 with random port */
await listen(server, { host: '127.0.0.1', port: 0 })
License
async-listen © microlink.io, released under the MIT License. Authored and maintained by microlink.io with help from contributors.
microlink.io · GitHub microlink.io · Twitter @microlinkhq
0.0.0
1 year ago