title: ExpressJS Converting Timestamp to mm/dd/yyyy in Route
body: <p>I am trying to convert my timestamp into mm/dd/yyyy format to be display on my index page and I have the function to do so, but I'm not sure how I should be calling it within my route to be used for display.</p>
  
  <p>My current setup comes back with an error, <code>TypeError: Cannot call method 'getMonth' of undefined'</code></p>
  
  <p>route:</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var blogDB = require('../config/blogDB.js');
  var Blogpost = require('./models/blogModel.js');
  var paginate = require('express-paginate');
  
  //index 
  router.use(paginate.middleware(10, 50));
  
  
              function dateDisplayed(date){
                  var dateCreated = (date.getMonth() + 1 + '/' + date.getDate() + '/' + date.getFullYear());
              }
  
      router.route('/') 
  
  
          // START GET method
          .get(function(req, res, next) {
  
              Blogpost.paginate({}, req.query.page, req.query.limit, function(err, pageCount, blogpost, itemCount) {
  
  
  
  
                  if (err) return next(err)
  
                          if (err)
                              res.send(err);
  
  
                          blogpost.title = req.body.title; // get the blog title
                          blogpost.author = req.body.author; // get the author name
                          blogpost.tagline = req.body.tagline; // get tagline
                          blogpost.content = req.body.content; // get the blog content
                          blogpost.category = req.body.category; // get the category
                          blogpost.tags = req.body.tags; // get the tags
                          blogpost.date = dateDisplayed(req.body.date);
  
  
  
  
  
  
                          res.format({
                              html: function() {
                                  res.render('pages/index', {
                                      blogpost: blogpost,
                                      pageCount: pageCount,
                                      itemCount: itemCount
                                  })
                              },
                              json: function() {
  
                                  res.json({
                                      object: 'blogpost',
                                      has_more: paginate.hasNextPages(req)(pageCount),
                                      data: blogpost
                                  })
                              }
                          }); // END res.format(html, json)
              }); // END Blogpost.paginate
          }); // END GET method
  
  router.route('/admin/posts/create')
  
      // START POST method
          .post(function(req, res) {
  
              console.log("New instance");
  
              var blogpost = new Blogpost(); // create a new instance of a Blogpost model
  
              blogpost.title = req.body.title; // set the blog title
              blogpost.blogUrl = blogpost.title.toLowerCase().replace(/\s+/g,"-");
              blogpost.author = req.body.author; // set the author name
              blogpost.tagline = req.body.tagline; // set the tagline
              blogpost.content = req.body.content; // set the blog content
              blogpost.category = req.body.category; // set the category
              blogpost.tags = req.body.tags; // set the tags
                  //Save Blog Post
                  blogpost.save(function(err) {
                      if (err)
                          res.send(err);
  
                      res.redirect(303, '/'); //NEEDS TO BE CHANGED
                  });
  
          }) // END POST method
  
  
          .get(function(req, res) {
              res.render('pages/blogpost-create');
          });
  
  module.exports = router;
  </code></pre>
  
  <p>blogModel.js:</p>
  
  <pre><code>var mongoose    = require('mongoose');
  var mongoosePaginate = require('mongoose-paginate');
  var Schema      = mongoose.Schema;
  
  
  
  var BlogPostSchema  = new Schema({
          title: String,
          blogUrl: String,
          author: String,
          tagline: String,
          category: String,
          content: String,
          tags: { type: String, lowercase: true },
          date: { type: Date, default: Date.now }
  });
  
  BlogPostSchema.plugin( mongoosePaginate );
  
  var Blogpost = mongoose.model("Blogpost", BlogPostSchema);
  
  
  
  module.exports = mongoose.model('Blogpost', BlogPostSchema);
  </code></pre>
  
  <p>index.ejs:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;% include ../partials/head %&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;header&gt;
          &lt;% include ../partials/header %&gt;
      &lt;/header&gt;
  
      &lt;div class="grid"&gt;
          &lt;div class="col-9-12"&gt;
              &lt;div class="blog-content"&gt;
                  &lt;% blogpost.forEach(function(blogpost) { %&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;h2&gt;&lt;a href="#" class="blog-title"&gt;&lt;%= blogpost.title %&gt;&lt;/a&gt;&lt;/h2&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;h3&gt;&lt;%= blogpost.date %&gt;&lt;/h3&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;h3 class="blog-category"&gt;&lt;%= blogpost.category %&gt;&lt;/h3&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;h3 class="blog-tagline"&gt;&lt;i&gt;&lt;%= blogpost.tagline %&gt;&lt;/i&gt;&lt;/h3&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;p&gt;&lt;%=: blogpost.content | truncate:800 | append:'...' %&gt;&lt;/p&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;a href="/blog/&lt;%= blogpost.blogUrl %&gt;" class="blog-read-more"&gt;Read More&lt;/a&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;% }); %&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="col-3-12"&gt;
              &lt;div class="sidebar-personal-information"&gt;
                  &lt;div id="sidebar-social-media"&gt;
                      &lt;ul id="sidebar-social-media-list"&gt;
                          &lt;li&gt;&lt;img class="sidebar-social-media-icons" src="images/linkedin.png"&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;img class="sidebar-social-media-icons" src="images/twitter.png"&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/div&gt;
                  &lt;div id="sidebar-current-titles"&gt;
                      &lt;h3&gt;Analytics Strategist&lt;/h3&gt;
                      &lt;h4&gt;&lt;a href="#"&gt;Resolute Digital&lt;/a&gt;&lt;/h4&gt;
                  &lt;/div&gt;
                  &lt;div id="sidebar-short-summary"&gt;
                      &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean a massa ante. Vestibulum eu enim est. Curabitur a leo venenatis, semper tellus ac, venenatis nisi. Fusce magna urna, cursus quis egestas et, tincidunt ut nisi. Suspendisse potenti. Praesent congue nec lectus vel posuere.&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="sidebar-newsletter-signup"&gt;
                  &lt;h3&gt;NEWSLETTER&lt;/h3&gt;
                  &lt;p&gt;Sign up for my weekly newsletter&lt;/p&gt;
                  &lt;form id="email-sign-up-form"&gt;
                      EMAIL: &lt;input type="email" id="email-field" placeholder="johndoe@gmail.com"&gt;&lt;/input&gt;
                      &lt;br&gt;
                      &lt;br&gt;
                      &lt;input id="email-submit" type="submit" value="SUBMIT" /&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
              &lt;% include ../partials/paginate %&gt;
      &lt;/div&gt;
  
  
  
  
      &lt;footer&gt;
          &lt;% include ../partials/footer %&gt;
      &lt;/footer&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>