DEV Community

loading...

Discussion on: 💪 Express.js on steroids: an OOP way for organizing Node.js project [starring TypeScript]

Collapse
mbisurgisoshace profile image
mbisurgisoshace • Edited

That is because the functions are not being called like a regular class method, so for intance AuthController.method(). They are being called as callback functions by express, so the 'this' keyword reference is lost. The way to solve it is to bind the 'this' context. So for example in this case, where you have handler: this.handleLogin, you just need to do this.handleLogin.bind(this). Hope this was helpful!