I'm starting a node app like this:
var express = require('express');
var jade = require('jade');
app.set('view engine', 'jade');
var app = express();
var env = process.env.PORT || 3000;
app.listen(env, function(req, res){
console.log('i am working!');
});
But I'm getting this error while I run my app...
D:\myLogin>node app
D:\myLogin\app.js:5
app.set('view engine', 'jade');
^
TypeError: Cannot call method 'set' of undefined
at Object.<anonymous> (D:\myLogin\app.js:5:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
What is missing here?
In here :
app.set('view engine', 'jade');
var app = express();
you assign a value to app
after you call a function on that value. So of course app
is undefined
when you do the set
.