Reputation: 51
I'm trying to use express with Pug (Jade) to render/display a page and the function get() is coming back undefined with warnings...
I've run:
npm install express --save
npm install pug --save
Heres the top of the JS file with undefined get method...
var app = require('express')();
app.set('view engine', 'pug');
app.get('/', function (req, res) {
console.log("test"); //line isn't reached
res.render('index', { title: 'Hey', message: 'Hello there!' })
});
No errors when running, it just doesn't work.
Upvotes: 0
Views: 759
Reputation: 2231
You need to start the express server by
app.listen(9000, function(){
console.log('Server started...');
});
Add this line to the bottom of your JS file. Then open your browser and hit the url:
localhost:9000
Only then will the GET method call be invoked by express.
Upvotes: 3