How can I format a date coming from MongoDB?

I had exactly this requirements (expressjs, mongoose, jade) and this is how I solved it for myself.

First of all I installed momentjs with npm install moment.
Then I passed moment to view using this:

var moment = require('moment');

app.get("https://stackoverflow.com/", function(req, res){
    // find all jobs using mongoose model
    Job.find().exec(function(err, items){
        // pass moment as a variable
        res.render('status', { 'jobs': items, moment: moment });
    })
});

Then using it like this in Jade:

table
  tr
    td Subject
    td Posted at
    td Status
  each job, i in jobs
    tr
      td #{job.subject}
      td #{moment(job.postedAt).format("YYYY-MM-DD HH:mm")}
      td #{job.status}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)