Skip to content

Instantly share code, notes, and snippets.

@MonksterFX
Created April 1, 2022 08:22
Show Gist options
  • Save MonksterFX/552fe951da2a99b77aabd353f7c2455f to your computer and use it in GitHub Desktop.
Save MonksterFX/552fe951da2a99b77aabd353f7c2455f to your computer and use it in GitHub Desktop.
promisify express app.listen with server as return value
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