11

Installing some npm packages globally is evil sometimes. I don't want to install jasmine like that:

npm install -g jasmine

How can I install and use jasmine without -g attribute?

Sergiy Seletskyy
  • 16,236
  • 7
  • 69
  • 80
  • 1
    Installing global npm packages isn't necessarily evil. For some packages, you actually want to use a global install, for example `yo`. Whether to install a package globally or locally is completely subjective. – Achrome Nov 14 '15 at 15:04
  • In general, packages used across applications should be globally installed and specific ones should be local. Applies to any tool you use.. – NitinSingh Aug 08 '17 at 04:27
  • @NitinSingh Quick nitpick here: The [Jasmine docs recommend you **don't** install it globally](https://jasmine.github.io/setup/nodejs.html): "_[A global install] is not recommended, however, since it’s difficult to keep the globally installed jasmine version in sync with each project that uses it._" Subjective advice? Fair. `;^)` But probably also the voice of experience. – ruffin May 20 '22 at 01:34
  • On local machine, if u chose to upgrade a package, you usually update it across all projects one is working on.. and if you are working on too many projects, its a challenge of a different aspect to tackle :) – NitinSingh May 20 '22 at 09:20

1 Answers1

20

1) You need to init an npm project. On the 5-th step of the wizard (question test command:) input jasmine

npm init

1b) If you init npm project before, make sure you have these lines in your package.json

"scripts": {
  "test": "jasmine"
},

2) Install jasmine as a local dependency

npm i --save-dev jasmine

3) To init jasmine (alternative for global jasmine init)

npm test init

4) To create example tests (alternative for global jasmine examples)

npm test examples

5) To run tests (alternative for global jasmine)

npm test 

--
P. S. Save your global environment :)

Sergiy Seletskyy
  • 16,236
  • 7
  • 69
  • 80