5

i tried running

$npm install mocha --save-dev 

and then

$mocha

the result is

$-bash: mocha: command not found

If install it globally it works but what if I want to use a package version on this project only

Is there a way to make it works without installing it globally?

I am on a mac 10.11 el capitan

Crimeira
  • 149
  • 10
  • try to change the param order... try this: npm install --save-dev mocha – Giordano Feb 02 '17 at 11:51
  • 1
    Here is the answer: http://stackoverflow.com/a/24497202/5048383 – dNitro Feb 02 '17 at 11:57
  • i tried it didnt work ,i even triend deleting the node_modules folder – Crimeira Feb 02 '17 at 11:57
  • The answer suggests to install it as a global or to use npm test .. is there a way to make work without it ? – Crimeira Feb 02 '17 at 12:04
  • answer suggests use: `node_modules/.bin/mocha` or `node_modules/mocha/bin/mocha` to run mocha locally or just add `"test": "mocha"` to npm scripts and run locally installed mocha with `npm test` and there is no other way. – dNitro Feb 02 '17 at 12:09
  • i was following this tutorial https://www.youtube.com/watch?v=Q8Jl85FJz4E&list=PLw5h0DiJ-9PAdZwGJCYb7a9P2mJHayQQ3 and she is able to do it is it no longer available ? (skip to 2:09) – Crimeira Feb 02 '17 at 12:16
  • 1
    @Crimeira, It never been available. Video editing magic and she forgot to explain that she has mocha globally installed. some people also complained about that in comments: *`npm install mocha --save-dev` will not give you the commanline, `npm install mocha -g` will do it.* – dNitro Feb 02 '17 at 12:33
  • thanks for the attention its now clear – Crimeira Feb 02 '17 at 13:12

4 Answers4

6

You can use the npx command to run local dependencies

Try the command:

 npx mocha
Bsquare ℬℬ
  • 4,423
  • 11
  • 24
  • 44
TheKnightCoder
  • 741
  • 6
  • 4
3

Since you haven't installed mocha globally you have to point terminal to your package's local directory

Run this command instead:

./node_modules/.bin/mocha

this will run the locally installed mocha package.

Mrinmay
  • 143
  • 1
  • 7
-1

To use a command installed from an NPM package, you have to install it globally. Try:

$ npm i -g mocha

If you don't want to install it globally, then you can use the local mocha command from:

$ <app>/node_modules/.bin/mocha
sampathsris
  • 21,564
  • 12
  • 71
  • 98
-1
$ cd project_directory

If you already have the dependency in package.json file -> do

$ npm install

$ ./node_modules/.bin/<module-name> -V // to get the version
$ ./node_modules/.bin/<module-name> <action> // to use that module

else, if you want to install a new module, firstly do ->

$ npm install <module-name> --save-dev

and then use the commands to get the version and use the module. In this way you will be able to set up and use specific node_modules for a particular project which is a good practice and make your project easy to share. To install modules globally, run ->

$ npm install -g <module-name>

or with sudo privileges ->

$ sudo npm install -g <module-name>

I hope this helps :) :)

Nandit Mehra
  • 346
  • 4
  • 12