jmar777 / node-async-router

A zero-boilerplate solution for using ES7 async functions in Express and other middleware-based web frameworks.
MIT License
24 stars 2 forks source link

Replacing express.Router()? #2

Open jzaefferer opened 6 years ago

jzaefferer commented 6 years ago

Are these two lines equivalent?

var router = require('express').Router()

var router = require('node-async-router')()

If that's correct, its still very simple to replace the built in router (see also https://expressjs.com/en/guide/routing.html#express-router ), but it might also be useful to mention this in the readme.

jmar777 commented 6 years ago

If I understand correctly, you're asking if there's any reason to use the Router exported by this module, as opposed to the one exported by Express? If so, then the answer is yes. This module works by patching pillarjs/router (which was originally extracted from Express, but removes the Express dependency).

Without applying these patches, async route handlers that resolve to a rejected Promise won't be handled correctly.

jzaefferer commented 6 years ago

Sorry, that's not what I meant. "equivalent" was not a good choice.

Since your example is for the standalone router package, but I'm using the built-in Router from Express, I was looking for a confirmation that the two are compatible.

pillarjs/router itself doesn't claim any explicit compatibility with Express - I guess the term "middleware" implies it?

jmar777 commented 6 years ago

Ahh, I'm not sure I'm 100% comfortable in asserting complete compatibility. I'm not specifically aware of any differences, and when we migrated a pretty large codebase over to this module, there weren't any issues.

Hopefully @dougwilson wouldn't object to weighing in on this, as he's still active in both repos? TL;DR: is pillarjs/router still API-compatible enough with express.Router to advertise as a drop-in replacement, or are their known incompatibilities at this point?