title: Before filter for all post requests in node.js
body: <p>I have the below code in my node.js app.js:</p>
  
  <pre><code>var express = require('express')
      ,cors = require('cors')
      ,app=express();
      var users = require('./routes/users');
      //some other codes
      .....
      app.use('/', routes);
      app.use('/users', users );
  </code></pre>
  
  <p>If a request is made to <code>/users/adduser</code>, it will go to the <code>users.js</code> in the routes folder.</p>
  
  <p>Now I want to add a filter which will capture all the POST requests and do some validations and only if the conditions are satisfied the POST should go to its handler.</p>
  
  <p>I.e if i get a <code>/users/adduser</code> with a POST request, before going to the method in the users.js in the routes folder, I should be able to capture that request and stop it if the condition is not met.</p>
  
  <p><strong>UPDATE 1</strong>
  Now i am having this app.use function, but in the result i am getting undefined as its not waiting till the function is returning value </p>
  
  <pre><code>app.use(function (req, res, next) {
      req.db = db;
      if (req.method != "POST") {
          next();
      }
      else {
          var userData = req.body;
          var result = Check(userData);
          if(result){
          next();            
          }
      }
  });
  
  function Check(userdata) { 
  
      var url = "someurl"+userdata.Id;
  
      var request = require("request");
      request({
          url: url,
          json: true
      }, function (error, response, body) {
  
          if (!error &amp;&amp; response.statusCode === 200) {
              if (response.toJSON().body.id == userId) { 
                  return true;
                  // i also tried next();
              }  
          }
      })
  };
  </code></pre>