Make app.listen() return a promise
See original GitHub issueNode’s native listen() method takes a callback that gets executed once the server is ready. I expected the koa listen() to return a promise, but apparently it doesn’t. This would be very helpful when setting up tests, for example in a mocha before hook, which understands promises:
describe('my app', function () {
before(async function () {
let app = koa()
app.use(router)
await app.listen()
})
})
This example of course would also work without async/await by returning the promise.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:13
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Express app.listen returns Promise { Server {} } - Stack Overflow
I have a startup function that connects to database, then returns a Server with app.listen(). The issue is that if I return app.listen...
Read more >Promisify server.listen · Issue #21482 · nodejs/node - GitHub
Problem: const server = app.listen(); console.log(`Server listening ... I'd too prefer that listen() would return a Promise whenever there ...
Read more >Express.js | app.listen() Function - GeeksforGeeks
listen() function is used to bind and listen the connections on the specified host and port. This method is identical to Node's http.Server....
Read more >Using Promises With Express JS - Turtle-Techies
In this article, we'll look at a variety of tactics developers use in the wild to promisify their Express apps.
Read more >Using Express.js Routes for Promise-based Error Handling
Find out how to enable promise-based route code and centralize both error ... Here we create an Express.js app and add some basic...
Read more >Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah I do this now
This works, I’m just sick of promisifying everything. But maybe mz will add http one day. But I must disagree with @juliangruber, there is a notion of promises in koa… Koa supports async functions as middleware, yielding of promises, … co moved to promises and I think koa should slowly move too, since async/await is definitly the future. But this “small” change is really out of scope if I look at the tests and they rely on getting the httpServer from app.listen() everywhere.
@felixfbecker works w/ bluebird 😃