I am trying to set a response message to the user, but when I do I get an error. (Cannot read property 'message' of undefined) This is the code that doesn't work:
server.js
const server = express();
let App = require('./controllers/app');
App = new App();
server.use('/', App.router);
http.createServer(server).listen(8080);
app.js
class App {
constructor () {
this.message = '';
}
router (request, response) {
if (request.url === '/register') {
response.render('register.ejs', {
url: request.url,
header: headBase + 'register',
message: this.message, // This is where the error is triggered
user: username
});
this.message = '';
}
}
}
Anywhere i try to set or read this.message
in the router method i get the error.