thanks_in_advance
thanks_in_advance

Reputation: 2743

share node.js modules across React apps?

I'm trying out node.js and npm for the first time, to code a React tutorial using the Create React App boilerplate.

The first simple app is working fine.

The file structure looks like this (Windows 7):

file structure of node.js app created with the Create React App boilerplate

My concern is that the node_modules folder is 70mb on file and occupies 120mb on the disk.

It seems that each time I create a new app via Create React App, the same folder is going to get re-created for the new app, and occupy a similar vast amount of storage.

My question is: is there some way to create new apps such that the same modules are not downloaded and don't end up occupying more and more storage, and can instead be shared across apps (not sure if node.js philosophy supports sharing of such modules).

Update: I have supplied my own answer to this question.

Upvotes: 2

Views: 664

Answers (2)

thanks_in_advance
thanks_in_advance

Reputation: 2743

I'm new to the node.js and npm way of doing things. It seems that this is the normal way of doing things, and dependencies are scoped to single projects. There are many advantages to doing it this way, and I no longer want to share the modules folder across different projects.

Upvotes: 0

RebelWithoutAPulse
RebelWithoutAPulse

Reputation: 442

You can install npm modules globally with the flag -g, like so:

# npm install -g jshint

That way they would be accessible to all your projects. See docs on npm install for details.

P.S. Separate advice - make sure you use somehat new (>=3.X) version of npm - otherwise you might run into problems with long file paths on Windows.

Upvotes: 3

Related Questions