Express Js 'this' Undefined After Routing With App.get(..)
I have a basic Node JS server which is designed to be used as an API, I've created a log and database module and I've started adding other modules to deal with different request ty
Solution 1:
You need to properly bind the function.
app.get('/v1/group', group.getAll);
only passes the getAll
function as a handler, but the function itself has no concept of this
. this
is decided based on the context that is bound, or based on how the function is called. This blog post is useful for understanding how function context works.
app.get('/v1/group', group.getAll.bind(group));
Post a Comment for "Express Js 'this' Undefined After Routing With App.get(..)"