title: Getting error of "cannot get" while making an api in express js
body: <p>I am working on to make REST API in express js but getting an error "Cannot GET /api/bears".
  here is my code </p>
  
  <p>server.js</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var bodyParser = require('body-parser');
  var mongoose   = require('mongoose');
  var Bear = require('./app/models/bear');
  
  mongoose.connect('mongodb://localhost/api', { useNewUrlParser: true }); // connect to our database
  
  
  
  
  app.use(bodyParser.urlencoded({ extended: true}));
  app.use(bodyParser.json());
  
  var port = process.env.PORT || 3000;
   //routes for api
   var router = express.Router();
  
  
  router.use(function(req, res, next) {
  
      console.log('Something is happening.');
      next();
  });
  
   router.get('/',function(req,res){
      res.json({message: "Welcome to my Api"});
   });
  
   router.route('/bears')
  
      .post(function(req,res){
          var bear = new Bear();
          bear.name = req.body.name;
  
  
          bear.save(function(err){
              if(err)
              {
                  res.send(err);
              }
              res.json({message: 'bear created!'});
          });
      });
  
   app.use('/api', router);
  
   app.listen(port);
   console.log("Magic happens on port" + port);
  </code></pre>
  
  <p>app/models/bear.js</p>
  
  <pre><code>var mongoose     = require('mongoose');
  var Schema       = mongoose.Schema;
  
  var BearSchema   = new Schema({
      name: String
  });
  
  module.exports = mongoose.model('Bear', BearSchema);
  </code></pre>
  
  <p>On localhost:3000/api, everything works fine but on localhost:3000/api/bears I am getting <strong>Cannot GET /api/bears</strong></p>
  
  <p>Could anyone help me where I am missing?</p>