I am working on a npm module with a couple dependencies. Now, should i publish the dependencies along with my product via the node_modules folder or not?
No you should not.
You should list all your dependencies in your package.json and publish that.
Your node_modules folder is automatically created when doing an npm install of the module, or npm install in a directory with a package.json.
Related
I want to npm install a broken package, i.e., the installation process does not work properly and results in an error. I am used to npm keeping the successfully installed packages in the local node_modules folder. For some reason npm has stopped doing that and removes the node_modules folder if the install is not successful.
How can I tell npm to keep the local node_modules folder regardless of the success or failure of the installation process?
I faced a similar problem when one of the packages failed to build its C++ addon and npm removed node_modules. The below steps helped me:
Install the packages with scripts disabled.
$ npm install --ignore-scripts
Fix the package
...
Rebuild the package
$ npm rebuild PACKAGE
How can I find the package.json for npm that lists all globally installed packages? I know I can find the root with npm root -g, but I cannot find the package.json in that directory.
If you run npm list inside the node_modules directory, it will list all the globally installed modules.
I deleted a folder under node_modules by mistake, should I run npm install in the project root to recover the deleted files without deleting the entire node_modules folder or should i delete the node_modules first and then run npm i?
If I run npm install without deleting the node_modules folder; will npm install only add the missing package files under the node_modules?
You probably must be having package.json present in your project root directory. If you have so, then you can then directly run npm install and all the packages and dependencies will be restored.
when I run npm install all of the dependencies will not load in their own folder but instead install them in my node_modules folder so I end up with 50 or so folders. Is there a way to get dependency packages node_modules to stay within that dependencies folder?
Is the structure of dependencies in node_modules simply a mirror of the dependency tree structure found in package.json? Or does performing npm install download what is in package.json and organize node_modules in some special way?
Ideally package.json will correspond to node_modules. Running npm install (with no arguments) will install all the packages described in package.json into node_modules, but running npm install somepackage won't modify package.json unless you use the --save option.
You can also use npm list to check if your node_modules and package.json are in sync. Packages in package.json that aren't in node_modules are tagged UNMET DEPENDENCY, whereas packages in node_modules but not in package.json are tagged extraneous.
Also note that the root package.json doesn't contain the full dependency tree; it only contains the list of direct dependencies. Dependencies of dependencies are listed in the package.json files of the dependencies themselves, recursively.