I think everyone knows that it's a bad practice to do other things (including returning something) after sending the response in express.js (there are very special cases though, but they don't include the one you shared).
I have great experience in IT over 12 years: front / back - ends, mobile, system administration and deployment cycle. I implement effective and great software products.
Yes, my idea to hide real response in a route is not a good idea.
Cause you have mixed flow.
In one case, you can put return in other res.SOMETHING, but not both.
It makes harder to maintain and avoid potential fails in a development team.
I only use express.js to build APIs (I never render a template or something). So it's more like a convention (shortcut) as returing JSONs is what I do in 90% of the cases.
I have great experience in IT over 12 years: front / back - ends, mobile, system administration and deployment cycle. I implement effective and great software products.
Yep, this is why I started from this message: "This code is probably for the specific use case, but looks not good."
For example, if you return await ... with undefined you will go in hang situation.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Whoever writes code like that is negligent :)
It's like saying that express.js is too permissive for letting you write code like this:
I think everyone knows that it's a bad practice to do other things (including returning something) after sending the response in express.js (there are very special cases though, but they don't include the one you shared).
Yes, my idea to hide real response in a route is not a good idea.
Cause you have mixed flow.
In one case, you can put
return
in otherres.SOMETHING
, but not both.It makes harder to maintain and avoid potential fails in a development team.
Yep, I see your point and you're right in a way.
I only use express.js to build APIs (I never render a template or something). So it's more like a convention (shortcut) as returing JSONs is what I do in 90% of the cases.
Yep, this is why I started from this message: "This code is probably for the specific use case, but looks not good."
For example, if you
return await ...
withundefined
you will go in hang situation.