title: How to organize express middlewares better?
body: <p>I'm using node with express and the following code is working as expected.</p>
  
  <p>file <strong>app.js</strong></p>
  
  <pre><code>app.use(function (req, res, next) {
      fs.mkdir('uploads/', function (e) {
          if (!!e &amp;&amp; e.code !== 'EEXIST') {
              console.log('Error while trying to create upload folder: ' + err);
          }
          next();
      });
  }, upload.single('file'));
  </code></pre>
  
  <p>My question is whether there is better way to write it?
  I mean to separate the function logic to other file and require it?</p>