Installing packages locally rather than globally (npx)

I used to install packages globally (npm i -g truffle anyone?) but have now moved to installing locally as I often need different versions between projects.

I recently came across npx (I am new to the JavaScript world, sorry if this is really old news).
npx is a npm package runner which is installed along with npm.

This allows me to run local packages easily and even run packages I haven’t installed.

I also did a check of what I had installed globally.
npm list -g --depth 0
I then uninstalled everything I didn’t absolutely need globally, which was pretty much everything.

Would appreciate thoughts on local vs global.

4 Likes

:heart: being able to run packages without installing

npx cowsay OpenZeppelin

1 Like

Installing globally may cause issues when different projects require different versions, configurations, etc., and makes the whole project environment harder to reproduce (because it assumes global state). The only benefit is not having to type npx, so local installation is a big win for me.

3 Likes

Running things locally is the future. Python has virtualenv for years now and it solves a lot of issues.

1 Like

I suggest checking what you have installed globally:
npm list -g --depth 0

For me ganache-cli is installed globally as I use the one instance in lots of projects, whilst everything else is local.

$ npm list -g --depth 0
/home/abcoathup/.nvm/versions/node/v10.16.0/lib
β”œβ”€β”€ ganache-cli@6.5.1
└── npm@6.10.3
1 Like

I use @openzeppelin/cli so often I am going to try running globally for a while.

$ npm list -g --depth 0
/home/abcoathup/.nvm/versions/node/v10.16.0/lib
β”œβ”€β”€ @openzeppelin/cli@2.5.3
β”œβ”€β”€ ganache-cli@6.6.0
└── npm@6.11.3

I am back to just having ganache-cli installed globally

$ npm list -g --depth 0
/home/abcoathup/.nvm/versions/node/v10.21.0/lib
β”œβ”€β”€ ganache-cli@6.9.1
└── npm@6.14.5