title: 404 not found error while working with mean stack application
body: <p>I'm getting the error as 404 not found while trying to post data using postman in chrome.Any kind of help would be highly appreciated.</p>
  
  <p>I'm doing this application from the following link :<a href="https://www.youtube.com/watch?v=wtIvu085uU0" rel="nofollow noreferrer">https://www.youtube.com/watch?v=wtIvu085uU0</a></p>
  
  <p>here is my code.
  app.js</p>
  
  <pre><code>//importing modules
  var express=require('express');
  var mongoose=require('mongoose');
  var bodyparser=require('body-parser');
  var cors=require('cors');
  var path=require('path');
  
  var app=express();
  const route=require('./router/route');
  
  //connect to mongodb
  mongoose.connect('mongodb://localhost:27017/contactlistapp');
  
  //on connection
  mongoose.connection.on('connected',()=&gt;{
  console.log('successfully connected to database mongodb @27017');
  
  });
  
  mongoose.connection.on('error',()=&gt;{
  
      if(err)
      {
  
          console.log('Error in database connection:'+err);
      }
  
  
      });
  
  
  //port number
  const port=3000;
  
  
  
  //adding middleware-cors
  app.use(cors());
  
  //bodyparser
  app.use(bodyparser.json());
  
  //adding routes
  app.use('/api',route);
  
  //static files
  app.use(express.static(path.join(__dirname,'public')));
  
  //testing server
  app.get('/',(req,res)=&gt;{
  res.send('foobar');
  });
  
  
  app.listen(port,()=&gt;{
  console.log('serve started at'+port);
  
  });
  </code></pre>
  
  <p>route.js</p>
  
  <pre><code>const express=require('express');
  const router=express.Router();
  const contact=require('../models/contacts');
  
  
  //retrieving contacts
  router.get('/contacts',(req,res,next)=&gt;{
  contact.find(function(err,contacts){
      res.json(contacts);
  })
  
  });
  
  
  
  //retrieving data
  router.get('/contacts',(req,res,next)=&gt;{
  res.send('Retrieving the contacts list');
  
  });
  
  //add contacts
  router.post('./contact',(req,res,next)=&gt;{
  let newContact=new contacts({
  first_name:req.body.first_name,
  last_name:re.body.last_name,
  phone:req.body.phone
  
  })
  
  newContact.save((err,contact)=&gt;{
  if(err){
  res.json({msg: 'Failed to add contact'});
  
  }
  else{
  
      res.json({msg: 'contact added successfully'});
  
  }
  })
  
  });
  
  //delete contacts
  router.delete('./contact/:id',(req,res,next)=&gt;{
      contact.remove({_id:req.params.id},function(err,result){
  if(err)
  {
      res.json(err);
  }
  else{
  
      res.json(result);
  }
      })
      });
  
  
  module.exports=router;
  </code></pre>
  
  <p>contacts.js</p>
  
  <pre><code>const mongoose=require('mongoose');
  
  const ContactSchema=mongoose.Schema({
  first_name:{
      type:String,
      required:true
  },
  last_name:{
  
      type:String,
      required:true
  },
  phone:{
  
          type:String,
          required:true
      }
  
  });
  
  const contact=module.exports=mongoose.model('contact',ContactSchema);
  </code></pre>
  
  <p>Getting the following error in postman:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;title&gt;Error&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;pre&gt;Cannot POST /api/contacts&lt;/pre&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  
  The following is the json data i'm trying to post:
  
      {
          "first_name":"anand",
          "last_name":"reddy",
          "phone":"1234567813"
  
  
  
      }
  </code></pre>