title: Node.js express router.post returns 404 not found
body: <p>My express application seems to return <code>404 NOT FOUND</code> whenever im using a post request method in my routes file. GET-requests are working fine and i can only see <code>"GET"</code> requests in the console aswell, even if im using a post request.
  Is there some missing link between app.js and routes/index.js that might be causing this? </p>
  
  <pre><code>// routes/index.js
  router.post('/foo', function (req, res, next) {
  res.setHeader('Content-Type', 'application/json');
  res.send('You sent: sdadad to Express');
  })
  
  
  // App.js
  var express = require('express');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  var index = require('./routes/index');
  
  var app = express();
  var cors = require('cors')
  app.use(cors())
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  
  // uncomment after placing your favicon in /public
  //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  app.use('/', index);
  
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
  });
  
  // error handler
  app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};
  
  // render the error page
  res.status(err.status || 500);
  res.render('error');
  });
  
  module.exports = app;
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Not Found 404
  Error: Not Found
  at C:\Users\willow\Desktop\backend\app.js:29:13
  at Layer.handle [as handle_request] (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\layer.js:95:5)
  at trim_prefix (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:317:13)
  at C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:284:7
  at Function.process_params (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:335:12)
  at next (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:275:10)
  at C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:635:15
  at next (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:260:14)
  at Function.handle (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:174:3)
  at router (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:47:12)
  at Layer.handle [as handle_request] (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\layer.js:95:5)
  at trim_prefix (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:317:13)
  at C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:284:7
  at Function.process_params (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:335:12)
  at next (C:\Users\willow\Desktop\backend\node_modules\express\lib\router\index.js:275:10)
  at SendStream.error (C:\Users\willow\Desktop\backend\node_modules\serve-static\index.js:121:7)
  </code></pre>