node-async-router icon indicating copy to clipboard operation
node-async-router copied to clipboard

Replacing express.Router()?

Open jzaefferer opened this issue 7 years ago • 3 comments

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.

jzaefferer avatar Feb 02 '18 09:02 jzaefferer

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.

jmar777 avatar Feb 02 '18 16:02 jmar777

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?

jzaefferer avatar Feb 02 '18 18:02 jzaefferer

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?

jmar777 avatar Feb 02 '18 19:02 jmar777