Pujan Shah
Pujan Shah

Reputation: 845

is it possible to share same node modules between multiple projects?

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)?

Upvotes: 2

Views: 4377

Answers (2)

zmag
zmag

Reputation: 8251

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

Upvotes: 3

philarmour
philarmour

Reputation: 414

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

Upvotes: 2

Related Questions