how to handle multiple conncurrency request in node.js

I am trying to upload multiple images at simultaneously. in server side i have to create one unique folder for to keep that images .so how to make wait request until one request complete and send response to client. i have tried this one but when i send response i am getting this error Can't set headers after they are sent.so suggest me good solution . i am waiting for urs reply.

when i upload five images , in server side i have to check whether folder is already exist or not. if it is not exist i have to create new folder for that five images and then i have to check that folder reference is already exist or not in mongodb.if it is not exist i have to store that folder reference in mongodb.and then i have to send response to client. but here when i upload five image, five request is going to server so request is doing that terms before complete one request so same folder reference is storing and also it is creating five folder for five image.

   function myMiddleware(req, res, next)
    {

          console.info("inside myMiddleware");
           var handler = function()
          {
               console.info("middleware redundant. ActionDone, calling next");
                next();
          };


           EventManager.once("finished",handler);

           if (actionDone !== "working") 
           {

              actionDone = "working";
              function doneWaiting(){
         //  console.log("finished");
              actionDone = "finished";
              EventManager.emit( "finished" );  
           }
          setTimeout(doneWaiting, 500);
      }

I think that what you need here is implementing a lock on the function that checks/creates the folder and does the database check/create.

Take a look at this article to see an example