Reputation: 16
I am on a Windows 10 machine and can only install npm packages globally. From the command prompt I can run:
npm install -g mocha
mocha
And there is no problem. When I install the package locally and run the command I receive the following error.
npm install mocha
mocha
'mocha' is not recognized as an internal or external command, operable program or batch file..
Upvotes: 0
Views: 686
Reputation: 5860
With a local installation of mocha, you can invoke it with:
node_modules/.bin/_mocha
try node_modules/.bin/_mocha -h
Caveat - You have to be in the directory where you installed it.
Upvotes: 0
Reputation: 53799
If you use npm scripts you will be able to use the binaries from the local installations. Simply add a script to your package.json
file:
package.json
{
...
"scripts": {
"test": "mocha"
}
...
}
And then to run it, simply do:
npm run test
For some commands, there are aliases, for example you can do npm start
instead of npm run start
and npm test
instead of npm run test
. But for all other scripts, you will have to do npm run <name>
.
Upvotes: 1
Reputation: 1976
That's the way NPM works. The global installation path is the only path added to the environment variables. If you want to run something from a local install, try doing npm run <package>
, so for your example, npm run mocha
Upvotes: 0