Created
April 1, 2022 08:22
-
-
Save MonksterFX/552fe951da2a99b77aabd353f7c2455f to your computer and use it in GitHub Desktop.
promisify express app.listen with server as return value
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 app = require('express')(); | |
async function start() { | |
return new Promise((resolve, reject) => { | |
// The `listen` method launches a web server. | |
const server = app.listen(); | |
server.once('listening', resolve(server)).once('error', reject); | |
}); | |
} | |
async function run() { | |
const server = await start(); | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment