1

I have some code in my controller like following

const express = require('express');
const AuthService = require('../../services/auth');

let router = express.Router();

router.get('/login', AuthService.login);

Now when i call login method in my services, and call another method from inside login method like.

class Authentication {

  login (req, res) {
    this.notify();
    res.send({message: 'login method'});
  }

  notify () {
    console.log('this is just a notification method.');
  }
}

module.exports = new Authentication();

I get following error.

TypeError: Cannot read property 'notify' of undefined

I know it's context issue, But i don't know how to fix it. Thanks in advanced.

pawanpandey392
  • 711
  • 7
  • 15

0 Answers0