ZeroSevenTen
ZeroSevenTen

Reputation: 1394

How does NPM resolve & run scripts from package-json?

For curiosity's sake, I want to create a folder in node_modules and be able to run it as a script in package.json's "scripts", but I have not been able to find out how to.

I've noticed with other package.json scripts like "react-scripts" that they wont work in the command line, but will when NPM runs them. How does npm resolve scripts?

Does it have to be a legit package for NPM to run it? (Like, will it check against the NPM registry for if that package exists, or contains scripts?)

Upvotes: 0

Views: 1795

Answers (1)

Trott
Trott

Reputation: 70075

If a module has a ["bin" entry in its package.json]1, then npm will put the executable script specified by that "bin" entry into a .bin folder in node_modules.

When running a script with npm run, npm will put that node_modules/.bin directory first in the PATH so they are found with npm run but not when run directly from the shell.

Upvotes: 1

Related Questions