As I understand it, there are two ways to install Express.js.
npm install express
- either from package.json or via command line. This method will install express locally in your node_modules folder.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?
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>
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With