user1502286
user1502286

Reputation: 27

javascript what's the different between this two pieces of code?

I'm new to javascript and node. 1st:

app.get('/', function(req, res){
  articleProvider.findAll(function(error, docs){
      res.render('index.jade', { locals: {
        title: 'Blog',
        articles:docs
        }
      });
  });
});

2nd

app.get('/', function(req, res){
  articleProvider.findAll(function(error, docs){
      res.render('index.jade', {
        title: 'Blog',
        articles:docs
        }
      );
  });
});

1st code is from this tutorial http://howtonode.org/express-mongodb, but doesn't work. 2nd code did work, and i just don't know why? Other parts are exactly same.

Upvotes: 0

Views: 87

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311835

In earlier versions of Express you needed to put the vars you wanted to make available to your Jade template in the locals field of that parameter to res.render.

That changed in 3.x so that all the fields of that parameter are available to the rendered template as locals.

Upvotes: 3

Related Questions