title: Cannot find module 'cookie-Parser' -- aws elastic beastalk
body: <p>I completed my node, postgres, angular project and is working on deployment. I recently learned about aws elastic beanstalk and for 2 days now, i have been trying unsuccessfully to deploy my project on it :( . Its been two days and really frustrating. </p>
  
  <p>My project structure was like below initially </p>
  
  <p><img src="https://i.imgur.com/QmN5JYm.png?1" /></p>
  
  <p>I now changed it to below after reading here that express expect .bin/www to be the starting file. I also rename my server.js to main.js <a href="https://stackoverflow.com/questions/22795357/502-bad-gateway-deploying-express-generator-template-on-elastic-beanstalk"> Here</a></p>
  
  <p><img src="https://i.imgur.com/dGeW3p3.png?1" /></p>
  
  <p>Despite my attempt, my project is still showing "Bad gateway 502" after deployment. I read many post about this and spent many hours.</p>
  
  <p>My package.json was exactly below initially.</p>
  
  <pre><code>{
    "name": "nairamarket",
    "version": "1.0.0",
    "description": "",
    "main": "bin/www.js",
    "scripts": {
      "start": "NODE_ENV=production node bin/www.js",
      "test": "echo \"Error: no test specified\" &amp;&amp; exit 1"
    },
    "engines": {
      "node": "4.2.1",
      "npm": "2.14.7"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
      "body-parser": "^1.15.2",
      "cookie-parser": "^1.4.3",
      "email-templates": "^2.3.0",
      "express": "^4.13.4",
      "express-session": "^1.13.0",
      "jade": "^1.11.0",
      "moment": "^2.12.0",
      "node-uuid": "^1.4.7",
      "nodemailer": "^2.2.1",
      "passport": "^0.3.2",
      "passport-local": "^1.0.0",
      "pg": "^4.4.4",
      "pg-hstore": "^2.3.2",
      "sequelize": "^3.19.2"
    },
    "devDependencies": {
      "bower": "^1.7.7",
      "nodemon": "^1.8.1",
      "morgan": "^1.7.0",
      "multer": "^1.1.0",
      "node-sass-middleware": "^0.9.7",
    }
  }
  </code></pre>
  
  <p>After analyzing my aws log , i saw cannot find module morgan. I then realised may be the npm install does not install devs. I then move </p>
  
  <pre><code>"morgan": "^1.7.0",
  "multer": "^1.1.0",
  "node-sass-middleware": "^0.9.7",
  </code></pre>
  
  <p>TO my dependecies . The error still persist for body-parser and cookie-parser. I then disabled the two to test and see. My problem still persist. When i analysed the logs again, below is what i saw.</p>
  
  <pre><code>npm ERR! Tell the author that this fails on your system:
  npm ERR!     NODE_ENV=production npm install &amp;&amp; node bin/www.js
  npm ERR! You can get information on how to open an issue for this project with:
  npm ERR!     npm bugs nairamarket
  npm ERR! Or if that isn't available, you can get their info via:
  npm ERR! 
  npm ERR!     npm owner ls nairamarket
  npm ERR! There is likely additional logging output above.
  </code></pre>
  
  <p>And under ngix error . I noticed the error below</p>
  
  <pre><code>[error] 7987#0: *2 connect() failed (111: Connection refused) while connecting to upstream, 
  </code></pre>
  
  <p>Below is part of my main.js and my bin/www.js just import the main.js</p>
  
  <pre><code>app.set('port', process.env.PORT || 8081);
  
  var server = app.listen(app.get('port'), function(){
      console.log('its listening', server.address().port);
      debug('Express server listen on port', + server.address().port)
  });
  
  debug('PORT' + process.env.PORT);
  debug('PARAM1' + process.env.PARAM1);
  debug('PARAM2' + process.env.PARAM2);
  debug('PARAM3' + process.env.PARAM3);
  debug('PARAM4' + process.env.PARAM4);
  debug('PARAM5' + process.env.PARAM5);
  </code></pre>
  
  <p>Please i would appreciate any tutorial or guidance with regard to this issue. Have worked on it for over two days and yet no solution.I also noticed like the node_modules/npm install is not restarting, like it has been cached . Please how do i addressed this issue and deploy my app ? Any help would be appreciated. </p>
  
  <p><strong>Update</strong></p>
  
  <p>I changed my start to</p>
  
  <pre><code>"start": "NODE_ENV=production npm install &amp;&amp; node bin/www",
  </code></pre>
  
  <p>as suggested my molda below. However, it does not reflect the changes . I deployed over 3 times , yet it display node bin/www.js regardless. </p>
  
  <p>I learnt that my zip or upload name need to match the name of my environment. I did do that. Now i am having the error below</p>
  
  <pre><code>fs.js:808
    return binding.readdir(pathModule._makeLong(path));
  </code></pre>
  
  <p>And for ngix</p>
  
  <pre><code> connect() failed (111: Connection refused) while connecting to upstream,
  </code></pre>
  
  <p>Althougth i don't quite understood what the error implies, i am suspecting my </p>
  
  <pre><code>_driname
  </code></pre>
  
  <p>I have a file call root.js and it contained is below.</p>
  
  <p>var path = require('path');</p>
  
  <pre><code>var dirname = path.resolve(path.resolve(__dirname));
  
  var rootPath = path.normalize(dirname);
  
  
  module.exports = rootPath;
  </code></pre>
  
  <p>I then reference my root.js in my config file which is two folders inward .</p>
  
  <p>config.js</p>
  
  <pre><code>var rootPath = require('../../root');
  </code></pre>
  
  <p>I am not sure if the error is related with that but i am quite suspecting. </p>