title: How to get a PUT route to work correctly (and not return 404 error) with Axios and Express?
body: <p>I have an app that makes this call:</p>
  
  <pre><code>handleUpdate (id, data) {
      const url = "/sites/" + id;
      axios.put(url, data)
          .then(res =&gt; {
              // handling of response
          })
          .catch(console.error);
  }
  </code></pre>
  
  <p>The route in the server.js file is:</p>
  
  <pre><code>router.route('/sites/:site_id')
     .put(function(req, res) {
     // handling of update 
  })
  </code></pre>
  
  <p>However, every time I make the handleUpdate call, I receive this message:</p>
  
  <pre><code>xhr.js:178 PUT http://localhost:3000/sites/5a39783d09ba9fec39b34d37 404 (Not Found) 
  </code></pre>
  
  <p>The id is correct, but I'm clearly not doing something right.</p>
  
  <p>Below is the applicable portion of the server.js:</p>
  
  <pre><code>//server.js
  'use strict'
  
  //first we import our dependencies...
  var express = require('express');
  var mongoose = require('mongoose');
  var bodyParser = require('body-parser');
  
  //and create our instances
  var app = express();
  var router = express.Router();
  
  //set our port to either a predetermined port number if you have set 
  it up, or 3001
  var port = process.env.API_PORT || 3001;
  
  
  //db config
  var mongoDB =  // my mlab database connection info;
  mongoose.connect(mongoDB, { useMongoClient: true })
  var db = mongoose.connection;
  db.on('error', console.error.bind(console, 'MongoDB connection error:'));
  
  //now we should configure the API to use bodyParser and look for JSON 
  data in the request body
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());
  
  //To prevent errors from Cross Origin Resource Sharing, we will set our 
  headers to allow CORS with middleware like so:
  app.use(function(req, res, next) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.setHeader('Access-Control-Allow-Credentials', 'true');
  res.setHeader('Access-Control-Allow-Methods', 
  'GET,HEAD,OPTIONS,POST,PUT,DELETE');
  res.setHeader('Access-Control-Allow-Headers', 'Access-Control-Allow-
  Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-
  Request-Method, Access-Control-Request-Headers');
  
  //and remove cacheing so we get the most recent comments
  res.setHeader('Cache-Control', 'no-cache');
  next();
  });
  
  //now  we can set the route path &amp; initialize the API
  router.get('/', function(req, res) {
  res.json({ message: 'API Initialized!'});
  });
  </code></pre>