sebdeckers / pfnp

:alien: Programming For Non-Programmers
19 stars 13 forks source link

npm install -global #20

Open yenlyng opened 8 years ago

yenlyng commented 8 years ago

Is there a difference if I install my npm in -globally or locally? What's the difference?

Had issues where I had installed the 'javascripting' pacakge successfully but I couldn't run it.

sebdeckers commented 8 years ago

The npm command itself is installed globally. That means you can invoke it on the command line (Terminal/Prompt) from any working directory.

A locally installed npm package is only available to JavaScript (Node.js) from within that directory and sub-directories. A globally installed npm package is available to Node.js from any directory on your system.

You typically want to install dependencies of your code locally. That way they are recorded in your project's package.json file. It lets others run npm install and be confident that everything will work. It also lets you use different versions of the same dependency across different projects. This is often needed since there can be breaking changes between versions of the same package.

The main reason for installing things globally is when you are using it as a system-wide tool. For example I like having rimraf installed globally as I run it from my command line to delete directories more easily than typing rm -rf. But if I wanted to use rimraf as a dependency in my app, I would still also install it locally for that project to ensure the dependency is installed in other environments than my laptop (e.g. other contributors, or testing/production environments).