Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the path of `package.json` to npm?

I use npm scripts to build my project. I'd like to be able to run the scripts from a different directory. That is, instead of doing the following:

cd project; npm run build; cd .. 

...I'd like to simply do something like:

npm run build -config project/package.json; 

or

npm run build -wd project; 

Is this possible?

like image 458
rinogo Avatar asked May 06 '16 18:05

rinogo


People also ask

Where is package JSON file located?

The package. json file is normally located at the root directory of a Node. js project. The name field should explain itself: this is the name of your project.

Where does npm install look for package json?

the package is installed in the current file tree, under the node_modules subfolder. As this happens, npm also adds the lodash entry in the dependencies property of the package. json file present in the current folder.

How do I specify Node js package json?

Use the engines keyword in the package. json file to specify the Node. js version that you want your application to use. You can also specify a version range using npm notation.


1 Answers

Using --prefix worked for me:

npm --prefix /path/to/project run build

Where path/to/project is the directory where your package.json with build command defined.

like image 62
Johnner Avatar answered Sep 16 '22 16:09

Johnner