I'm a noob to Angular development. I installed node.js and did a global install of the Angular cli (npm install -g #angular/cli). Nevertheless, I also have to npm install angular (without the -g option) in every Angular project. This creates a node_modules directory in the project and installs a LOT of files in that directory. Files that take up a lot of disk space.
Is there a way to do a global install of #angular/cli #angular/common, etc., then use that one set of global files in my projects?
I haven't found any documentation for doing so.
Thanks.
Related
Does it have an issue or conflicts if you install ionic and angular and then you install reactjs, apache-cordova and karma in npm ?
If you install these packages on the same project you may have issues. All these frameworks are meant to work independent and you shouldn't use Angular if already using React or vice versa for instance.
If the packages are installed on different projects, then you are good to go. The package is only used by the project you installed it on (you can find all the packages installed for a project on the node_modules folder inside your project).
I think there would be no issues as long as you install them globally. just add -g every time you npm install something.
I've got an iOS app, using google cloud functions and want to install the Request module/package https://www.npmjs.com/package/request in the node_modules folder.
My folder structure is:
- Desktop
- myApp
- firebase
- functions
- node_modules
I was reading up on npm about npm install and there was some stuff about installing locally, globally and some other things I didn't quite get.
Is there a standard way to install packages with npm?
And if I wanted to install "Request" in the terminal do i "cd" to the node_modules folder and npm install from there or is it from within the functions folder?
Thanks.
In the same directory where you have the node_module directory (i.e. in your functions directory) you should also have package.json file. If you are in that directory and you run npm install request --save then you will install the module and put it in the dependencies in package.json file. That is what installing locally means. For more info see:
https://cloud.google.com/functions/docs/writing/dependencies
(Cloud functions for Firebase work pretty much the same as Google Cloud Functions)
Update
The --save is the default behavior of npm install since v5.0 so you don't need to use the --save flag since the saving is done automatically (there is --no-save to prevent saving).
See the release notes for more info:
https://github.com/npm/npm/releases/tag/v5.0.0
I am quite new to npm but I have a question about npm node modules. I have the node modules now installed in several directories. One for Gulp, one for nodeJS etc. I was wondering how I could have one dedicated node modules directory and let the other packages point to that directory, instead of having node modules all over the place.
What is best practise?
Cheers,
Lino
Yes, you can have global node_modules directory accessible to multiple application.
A package is available globally if it is installed with -g option. For instance if body-parser is required globally it should be installed with the following npm command:
npm install body-parser -g
Following are the paths are usage of modules:
Local install (default): puts stuff in ./node_modules of the current
package root.
Global install (with -g): puts stuff in /usr/local or wherever
node is installed.
Install it locally if you're going to require() it.
Install it globally if you're going to run it on the command line.
If you need both, then install it in both places, or use
npm link.
Is that any difference npm install and just move whole module folders? In fact, I'm trying to deploy my node app to linux server, but there is some problem with npm install so I move my node_modules folder entirely to linux server, apparently no problem with it.
Is it possible to be troubled this way later?
npm install doesn't just copy code from the Internet to node_modules. The installation might also compile code for the platform.
So if you are copying from/to the same platform it should be OK. Though even then some modules might not work depending on the environments.
npm install read package.json and install all missing modules in node_modules folder. There is no problem if you just copied node_modules folder from your source.
But if you want to install any new module then use:
npm install package-name --save (or -g if you want to install globally) so that your package.json can track new modules.
Kinda 2 questions related to each other here.
When doing a brew install node, should I first navigate to the root of whatever folder I'm going to hold all my future web projects/apps then run it? Or does it not matter where I run the install initially for Node? Because I notice it creates a node_modules folder in /local/lib/node_modules
I assume it doesn't matter, and when you start installing node packages using npm install [package] it'll create a separate node_modules folder under the context you're in so lets say /www/MyApplication run npm install and it'll create /www/MyApplication/node_modules....and that the one under /local/lib/node_modules just serves as the one for npm itself because it needs its own root node_modules folder which is how npm runs?
Correct, it makes no difference where you run brew install node, it will install into your Homebrew folder.
When you use npm to install a Node module, it will install into the current directory, unless you use the -g global flag. Normally you will install modules that are project dependencies into your project folder, and global modules are for global utilities.
For example, to use Grunt you would install the grunt-cli package globally for the command-line utility.
npm install -g grunt-cli
And for each project that uses Grunt you will install a version of the grunt module for use with the project.
npm install grunt