mongodb - How to get user information from a given ID and display it using Node.js and EJS -
i have home page uses ejs template,
want display user's name (not user has logged in now) using user's id url
the page called this:
/home?id=235325325235
here part of home.ejs:
<!-- want username or other info of user --> <p> hello <%= get.otheruser.name(id) %> </p>
here part of routes.js
// load user model var user = require('../app/models/user'); app.get('/home', function(req, res) { res.render('home.ejs', { id : req.query.id, otheruser : user.findbyid( req.query.id ), //error doesn't info need currentuser : req.user //ignore this, information of current logged in user }); });
but, happens if logged in user want view home page of user?
he call home page id of other user,
/home?id=43565476535
i need function gets information using id url
how done node.js?
to answer question, found way.
app.get('/home', function(req, res) { //get user information based on id url parameter user.findbyid(req.query.id, function(err, doc) { res.render('home.ejs', { id : doc._id }); }); });
it needed findbyid user id using id url.
Comments
Post a Comment