I'm using latest npm, on a mac. I've got a strange problem: if I want to install some package locally on a folder, I'm forced to npm init
it. In other words, if I simply npm install [package name]
, it will install globally (in my /User/npm-modules folder), and thus the onnly way to install locally is to init the folder. So basically, the opposite it should normally do. Why? Any idea?
Asked
Active
Viewed 530 times
2

Luca Reghellin
- 7,426
- 12
- 73
- 118
2 Answers
7
npm init
creates package.json
file in your current project directory. npm packages will install locally when you have package.json
set up by using the command npm i PACKAGE-NAME
.

Usama Tahir
- 1,707
- 3
- 15
- 30
-
npm packages? That isn't a command. Did you mean npm install ? – Tony Abrams Nov 06 '18 at 10:58
-
1I just referred to npm packages. – Usama Tahir Nov 06 '18 at 10:59
4
Yes, if you want to install package localy, you need to create package.json file. This is what npm init will do and then you can install packages

Piosek
- 220
- 1
- 4
- 15
-
1ah ok, I didn't know it was by design, it's not documented on the npm-install entry of the official docs. Thank you. – Luca Reghellin Nov 06 '18 at 10:56