title: How to change directory. Multer/express.js
body: <p>I have two form like this</p>
  <pre><code>&lt;form action=&quot;/createFolder&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;&gt;
      &lt;input type=&quot;text&quot; name=&quot;folder&quot; id=&quot;year&quot; placeholder=&quot;enter year&quot;&gt;
      &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;student&quot; placeholder=&quot;enter your name&quot;&gt;
      &lt;input type=&quot;submit&quot; value=&quot;send&quot;&gt;
  &lt;/form&gt;
  
  &lt;form action=&quot;/upload&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
      &lt;label&gt;File&lt;/label&gt;&lt;br&gt;
      &lt;input type=&quot;file&quot; name=&quot;filedata&quot; /&gt;
      &lt;input type=&quot;file&quot; name=&quot;filedata&quot; /&gt;
      &lt;input type=&quot;file&quot; name=&quot;filedata&quot; /&gt;&lt;br&gt;&lt;br&gt;
      &lt;input type=&quot;submit&quot; value=&quot;Send&quot; /&gt;
    &lt;/form&gt;
  </code></pre>
  <p>in  the first one user enter data and my node.js script create two folders like this &quot;year/name&quot;</p>
  <pre><code>app.post('/createFolder', upload.none(), (req, res, next) =&gt; {
   const body = req.body;
   if (fs.existsSync(body.folder)) {
      console.log('Folder exist');
   } else {
      fs.mkdirSync(body.folder);
   }
   fs.mkdirSync(body.folder + '/' + body.name);
   updateStorageConfig(body.folder, body.name);
   res.redirect(&quot;/&quot;);
  </code></pre>
  <p>In the <strong>updateStorageConfig</strong> function i try to set <strong>multer.diskStorage()</strong> and then create app.post for my second form like this</p>
  <pre><code>function updateStorageConfig(folder, name) {
  storageConfig = multer.diskStorage({
      destination: (req, file, cb) =&gt; {
          cb(null, folder + '/' + name);
      },
      filename: (req, file, cb) =&gt; {
          cb(null, file.originalname)
      }
  });
  
  upd = (multer({storage: storageConfig}).array(&quot;filedata&quot;, 3));
  app.post(&quot;/upload&quot;, upd, function (req, res, next) {
      let filedata = req.files;
      if(!filedata)
          res.send(&quot;Error&quot;);
      else {
          res.end();
      }
  });
  </code></pre>
  <p>If i create the fist folders its work ok, but when i create another folders, files from second form downloads in old direction.</p>
  <p>How change the direction??</p>