Skip to content

Instantly share code, notes, and snippets.

@flameoftheforest
Last active October 12, 2021 07:31
Show Gist options
  • Save flameoftheforest/65bf710eb2efc93f761c848164b12be2 to your computer and use it in GitHub Desktop.
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
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