1

I'm trying to organize my ExpressJS app, like the accepted answer here. (I don't use subdomains, just subfolders) Currently my folder structure is like

root (expressjs project with its own package.json)
--api (expressjs project with its own package.json)
--panel (single page app)
--site (single page app)
package.json (root folders package.json)
app.js (root folders app.js)

My app.js at the root level is like

express()
.use(helmet())
.use(compression())
.use('/api', require('./api/app').app)
.use('/panel', express.static('./panel'))
.use('/', express.static('./site'))
.listen(port);

My app.js at the api project end with

exports.app = app;

I use Github to store my project and CodePipeline to deploy to Elastic Beanstalk. But it does not work, the EB instance is red. This is from the logs: (cors is a dependency of api project)

Error: Cannot find module 'cors'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/var/app/current/api/app.js:3:18)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
module.js:471
    throw err;

So my question is this, how can I install dependencies of subfolders during CodePipeline deploy?

Community
  • 1
  • 1
Emre
  • 388
  • 3
  • 10

1 Answers1

1

Solved by adding:

"scripts": {
  ...
  "postinstall": "cd api && npm install"
},

and a .npmrc file with

unsafe-perm = true

in it

Emre
  • 388
  • 3
  • 10