0

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.

9
  • Is the render working ? Your browser renders the index page ? have you started the express server ? Commented Sep 30, 2017 at 5:37
  • @v1shnu That line doesn't get reached, along with the console.log. app.set isn't throwing any errors or warning Commented Sep 30, 2017 at 5:39
  • 1
    Can you show me the code which has the express server running ? because without starting the server and without hitting the root url, the get method will not be invoked. Commented Sep 30, 2017 at 5:46
  • @v1shnu So i have a different server running and the app.get is inside the function I'm sending responses with. The lines above in this function get invoked (before and after the app.get). I can't figure out why the get method is undefined, but every other express function is fine Commented Sep 30, 2017 at 5:50
  • can you paste the full code here. It's very hard to debug with just that. Commented Sep 30, 2017 at 5:52

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.