DC1477
DC1477

Reputation: 321

Does bower install need to be run in the same folder as bower.json?

I'm using the express generator https://github.com/expressjs/generator and mixing the angular seed project https://github.com/angular/angular-seed into it to create a lightweight scaffold for a mean stack app.

I would like to be able to run npm start to install all dependencies including the front end ones. The problem is that the angular/front end related files are not in the root directory, but rather in the "public" sub-directory. I know I can create an npm start script which runs bower install but I don't know how to make the start script descend into the public sub-directory and then run bower install.

My question is does bower install try to find a bower.json file in sub-directories or does it stop searching after looking for the bower.json file in the working directory? If the former, then I can just run bower install without worrying about navigating down the folder structure manually.

If bower install won't search for bower.json in the sub-directory, how could I include this command as part of an npm start script? It seems the command would have to change directories into the "public" sub-directory and then run bower install.

Finally, this is mainly a deployment issue for me. I'm using heroku which, when deploying, automatically runs npm install and the start scripts when it detects the presence of the package.json file. So it seems that I need to include include bower install as part of the start scripts.

Upvotes: 1

Views: 1022

Answers (1)

rdegges
rdegges

Reputation: 33824

To answer your question: yes. bower install must run from the directory where your bower.json file exists.

You can most definitely create an npm start script which does this, however. It's easy! npm scripts are nothing more than shell commands that get executed verbatim.

So, let's say you've got a project that looks like this:

myapp
├── app.js
├── package.json
└── public
    └── bower.json

You can essentially create an npm start script that looks like this:

// ...
"start": "cd public && bower install && cd .. && node app.js"
// ...

This will ensure that when npm start is run, your bower dependencies get installed first, then your node app gets started.

Hope this helps!

Upvotes: 1

Related Questions