Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm keeps installing globally

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?

like image 712
Luca Reghellin Avatar asked Apr 08 '26 03:04

Luca Reghellin


2 Answers

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.

like image 190
Usama Tahir Avatar answered Apr 10 '26 15:04

Usama Tahir


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

like image 41
Piosek Avatar answered Apr 10 '26 16:04

Piosek