npm install pointing to specific package.json

sduser1
sduser1 used Ask the Experts™
on
I have added a command in scripts section of package.json to update one of the one of the dependencies.

When i run npm install, is there a way to tell the npm install to pick up specific package.json file?

Not sure how to get the npm install to use the package.json located in a local directory.

If i do a yarn install, i see it uses the package.json that was in the local directory.

If i use npm install -g command, the install does not use package.json from the local directory.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Why would you want to do that?

Not sure how to get the npm install to use the package.json located in a local directory.
When you run npm it should use the package.json in the folder that you are in.

How are you running npm - is this in a script or from the command line?

Author

Commented:
I am running the command

npm install -g

The reason I know that it is not using package.Json in the local project folder is that I have added a custom script in the scripts section of the package.json. It did not execute
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Try without the -g option.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Tried running the command npm install without the -g option.

it is failing due to git dependency

npm ERR! Command failed: /usr/local/bin/git checkout 0.3.2
npm ERR! error: pathspec '0.3.2' did not match any file(s) known to git

Can you help me how to fix this?
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
The error is saying there is something wrong with your git command. It is seeing the 0.3.2 as part of the git path - which is causing it to fail.

Does that command work on the command line when entered manually?

Author

Commented:
tried the command 'git checkout 0.3.2

Got the same error

Error log

6259 verbose stack Error: Command failed: git checkout 0.3.2
6259 verbose stack error: pathspec '0.3.2' did not match any file(s) known to git
6259 verbose stack
6259 verbose stack     at ChildProcess.exithandler (child_process.js:281:12)
6259 verbose stack     at emitTwo (events.js:126:13)
6259 verbose stack     at ChildProcess.emit (events.js:214:7)
6259 verbose stack     at maybeClose (internal/child_process.js:915:16)
6259 verbose stack     at Socket.stream.socket.on (internal/child_process.js:336:11)
6259 verbose stack     at emitOne (events.js:116:13)
6259 verbose stack     at Socket.emit (events.js:211:7)
6259 verbose stack     at Pipe._handle.close [as _onclose] (net.js:561:12)
6260 verbose cwd /Users/sdatla/repos/newton
6261 verbose Darwin 18.6.0
6262 verbose argv "/Users/sdatla/build_tools/node-v8.15.1-darwin-x64-npm-5.6.0/bin/node" "/Users/sdatla/build_tools/node-v8.15.1-darwin-x64-npm-5.6.0/bin/npm" "install"
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Well the obvious solution is to get your git command working first.

Once that is working put it in your package.json.

I am not a git expert but if I read this page https://git-scm.com/docs/git-checkout
It would appear that you are using the checkout command correctly.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial