As of now I am installing node modules every time for the new angular project. Is it possible to use one projects node modules to other project by configuring any file(like changing the path in any file so it can use that modules)?
-
1No, and you wouldnt want to the `node_modules` are specifc to that project, it gets generated from the package.json of the individual project – Smokey Dawson Dec 18 '18 at 05:40
-
Possible duplicate of https://stackoverflow.com/q/46470247/5043867 – Pardeep Jain Dec 18 '18 at 05:41
-
logically I would not but for learning purpose the same set of dependencies I required for the projects. – Pujan Shah Dec 18 '18 at 05:42
-
@PujanShah in the angular.json file of your project, you can update the value of "$schema": to the relative path of the node module folder. – Mayank Bansal Dec 18 '18 at 05:43
2 Answers
First off I was shocked to see that this is actually a thing that some people are doing - see: https://github.com/nodejs/help/issues/681
However I would advise against it.
The idea behind each project having its own node_modules folder (and package.json) is that each of your projects should specify its own dependencies (including specific versions) which is a good thing for stability, predictability, reproducibility, etc. of your various projects. Here's a pretty good write-up on the node dependency model: https://lexi-lambda.github.io/blog/2016/08/24/understanding-the-npm-dependency-model/
Now if you're talking about a local module (that you created yourself), you can have a look at https://docs.npmjs.com/cli/link.html

- 394
- 5
- 10
-
basically it should be different only, but as I mentioned for learning purpose there are multiple tasks(application) and all are having the same dependencies then we can create multiple applications in single project. – Pujan Shah Dec 21 '18 at 12:57
From Angular 6, you can generate multiple application in a single Angular project.
https://angular.io/cli/generate#application-command
applications generated by Angular cli command stay in same workspace and share node_modules.
For example, if you want to generate app my-project
:
ng generate application my-project
If its dependencies are not different from previous one, you can use --skipInstall=true
option with ng generate
command.
And ng serve
it with --project
option:
ng serve --project=my-project

- 7,825
- 12
- 32
- 42