title: Cannot read property 'push' of undefined in node_modules
body: <p>while running my first MEAN stack application i am getting this error:</p>
  <p>\contactlist\node_modules\express\lib\router\index.js:502
  this.stack.push(layer);
  ^</p>
  <p>TypeError: Cannot read property 'push' of undefined
  at Function.route (C:\Users\Mahima Kaushik\Desktop\contactlist\node_modules\express\lib\router\index.js:502:14)
  at Function.proto. [as post] (C:\Users\Mahima Kaushik\Desktop\contactlist\node_modules\express\lib\router\index.js:509:22)
  at Object. (C:\Users\Mahima Kaushik\Desktop\contactlist\routes\route.js:11:8)
  at Module._compile (internal/modules/cjs/loader.js:1251:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
  at Module.load (internal/modules/cjs/loader.js:1100:32)
  at Function.Module._load (internal/modules/cjs/loader.js:962:14)
  at Module.require (internal/modules/cjs/loader.js:1140:19)
  at require (internal/modules/cjs/helpers.js:75:18)
  at Object. (C:\Users\Mahima Kaushik\Desktop\contactlist\app.js:9:15)
  at Module._compile (internal/modules/cjs/loader.js:1251:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
  at Module.load (internal/modules/cjs/loader.js:1100:32)
  at Function.Module._load (internal/modules/cjs/loader.js:962:14)
  at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
  at internal/main/run_main_module.js:17:47</p>
  <p>contactlist/app.js</p>
  <pre><code>var express = require('express');
  var mongoos = require('mongoose');
  var bodyparser  = require('body-parser');
  var cors = require('cors');
  var path = require('path');
  
  var app = express();
  const route = require('./routes/route');
  
  //connect to mongodb
  mongoos.Mongoose.connect('mongodb://localhost:27017/contactlist');
  
  //on connection
  Mongoose.connection.on('connected',()=&gt;{
      console.log('connected to database mongodb @2717');
  });
  Mongoose.connection.on('error',(err)=&gt;{
      if(err)
      {
          console.log('error in database connection:'+err);
      }
  });
  
  
  //port number
  const port = 3000
  //adding middleware -cors
  app.use(cors());
  
  //boday-parser
  app.use(bodyparser.json());
  
  //static files
  app.use(express.static(path.join(__dirname,'public')));
  
  //add routes
  app.use('/api',route);
  //testing
  app.get('/',(req,res)=&gt;{
      res.send('contactlist');
  });
  
  app.listen(port,()=&gt;{
      console.log('server started at port:'+port);
  
  });
  </code></pre>
  <p>contactlist/routes/route.js</p>
  <pre><code>const { Router } = require('express');
  const express = require(&quot;express&quot;);
  const router = express.Router();
  //retrieving contacts
  router.get('/contacts',(req,res,next) =&gt;{
      res.send('retrieving the contact list');
  
  });
  
  //add contacts
  Router.post('/contact',(req , res, next)=&gt;{
  //logic
  });
  
  //delete contacts
  Router.delete('/contact/:id',(req , res, next)=&gt;{
  //logic
  });
  
  module.exports = router;
  </code></pre>