Last active
October 12, 2021 07:31
-
-
Save flameoftheforest/65bf710eb2efc93f761c848164b12be2 to your computer and use it in GitHub Desktop.
Async Start The ExpressJS Server Function - waits for the server to be ready before returning from function
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 startTheExpressServer = async (expressApp, port, key, cert) => { | |
const https = require('https'); | |
let server = null; | |
const promise = new Promise((resolve, _) => { | |
server = https.createServer({ | |
key, | |
cert, | |
}, expressApp).listen(port, async () => { | |
console.log(`server is listening to ${port}`); | |
resolve(); | |
}); | |
}); | |
await promise; | |
return server; | |
}; | |
exports.startTheExpressServer = startTheExpressServer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment