Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the benefits of installing Express.js locally vs globally

As I understand it, there are two ways to install Express.js.

  1. Using npm install express - either from package.json or via command line. This method will install express locally in your node_modules folder.
  2. Using npm install express -g . This method installs the package globally on your machine.

I was just wondering what the benefits were to using either method. Is either one considered "best practice" over the other?

like image 251
mshell_lauren Avatar asked Feb 10 '13 19:02

mshell_lauren


People also ask

What is the difference between npm install global and local?

local packages are installed in the directory where you run npm install <package-name> , and they are put in the node_modules folder under this directory. global packages are all put in a single place in your system (exactly where depends on your setup), regardless of where you run npm install -g <package-name>

Can Express be installed globally?

Firstly, you have to install the express framework globally to create web application using Node terminal. Use the following command to install express framework globally.

Should I install node js globally?

If you want to use it as a command line tool, something like the grunt CLI, then you want to install it globally. On the other hand, if you want to depend on the package from your own module using something like Node's require, then you want to install locally.

What is the difference between the global installation of dependencies and local installation of dependencies?

Installing the local dependencies means the module will be available only for a project you installed in the same directory. Global installing dependencies puts the module into your Node.


1 Answers

For creating an app, you should always install it locally. This will allow you to use different express version for each app you make.

Installing express globally will allow you to use the express command line utility to create boilerplate code and stuff. So ideally, you should install express in both places, but make sure the app you develop run on the local version.

like image 137
Simon Boudrias Avatar answered Nov 15 '22 19:11

Simon Boudrias