"npm install" independent of npmjs.org - node.js

npm install downloads packages from npmjs.org, compiles and then installs. So even if the node_modules folder is taken backup it can not be used on other machines where the os might be different, due to the native machine code generated during the npm install.
Also another problem with npm install is that it downloads from npmjs.org. What if the site goes down?. How to download the packages and the same package be installed offline on all platforms?

You can tell npm to use a mirror if npmjs.org is down. For example:
npm set registry http://registry.npmjs.eu/
Or with a runtime option:
npm --registry http://registry.npmjs.eu/ install express

If you do keep the node_modules directory with your code, you can simply run npm rebuild to re-compile anything that needs it.
Otherwise, you have a lot of options for installing from various locations. You could keep package tarballs locally. From the documentation:
npm install (with no args in a package dir)
npm install <tarball file>
npm install <tarball url>
npm install <folder>
npm install [#<scope>/]<name> [--save|--save-dev|--save-optional] [--save-exact]
npm install [#<scope>/]<name>#<tag>
npm install [#<scope>/]<name>#<version>
npm install [#<scope>/]<name>#<version range>
npm i (with any of the previous argument usage)

Related

Install node module from own gitlab server

I'd like to install node modules from our gitlab server. This is a link to a repository:
http://ABCD-GITLAB/myGroup/myNodeModule.git
According to the npm install guide the install command should be this:
gitlabUser: me
myProject: myNodeModule
npm install gitlab:mygitlabuser/myproject
I have no idea how to reference my
gitlab server url
group
project
account name
I tried some commands but all failed:
npm install gitlab:ABCD-GITLAB:me/myproject
npm install gitlab:ABCD-GITLAB:me/myproject.git
npm install gitlab:http://ABCD-GITLAB:me/myproject
npm install gitlab:http://ABCD-GITLAB:me/myproject.git
npm install gitlab:http://ABCD-GITLAB:me/myGroup/myproject
npm install gitlab:http://ABCD-GITLAB:me/myGroup/myproject.git
npm install gitlab:http://ABCD-GITLAB:me/myGroup/myproject.git
What is the correct way to reference a npm dependency, a clear structure would be great like
npm install gitlab:<serverUrl/>:<username/>/<groupname/>/<projectname/><gitsuffix>.git
I would try one of these:
npm install git+ssh://git#ABCD-GITLAB:myGroup/myNodeModule.git
npm install git+https://git#ABCD-GITLAB/myGroup/myNodeModule.git
npm install git://ABCD-GITLAB/myGroup/myNodeModule.git
You may need to change git to your username and you can add #v1.0.27 or something like that at the end for a specific version or tag:
npm install git://ABCD-GITLAB/myGroup/myNodeModule.git#v1.0.27
You can also install from a tarball:
npm install https://ABCD-GITLAB:myGroup/myNodeModule/repository/archive.tar.gz
You can add ?ref=master to the end of the tarball URL for the branch.

What NPM command should users run if the package.json file has been updated?

If I update the package.json file in an NPM workflow app, what command do existing users run to update their local node_modules dependencies?
To start using it, they run:
$ npm install
So what do they run if there is a change to the package.json file? Or do they just delete the folder and re-run the npm install command?
To re-validate the package.json and install adjusted versions or new packages:
$ npm install
The one thing this won't do is remove packages that aren't in package.json. To do that, run:
$ npm prune
If you've only changed package versions and not added new packages:
$ npm update
If you you've updated a specific package version:
$ npm update {packagename}
You should either do
npm install && npm prune
or
npm upgrade && npm prune
npm install will be faster than npm upgrade because it only updates packages in node_modules if package.json demands a newer version. npm uprade, on the other hand, will download updates to dependencies if they are available, which may include bug fixes. For ≥npm-5, you should use npm install because npm upgrade will have the side-effect of modifying any package-lock.json file which should not be modified unless if you are the package’s maintainer.
npm prune is necessary because the updates to package.json may have removed dependencies. If you do not run npm prune, packages installed by a prior version of package.json will remain in the node_modules directory that would not be there if you freshly downloaded/cloned the project and ran npm install. Due to how some packages conditionally call require() or even scan the node_modules directory, leaving packages which were removed from package.json can result in unexpected behavior.

How does npm know the path to install module from

I am new to npm, using package.json to define the dependencies. I am just curious where is those dependencies installed from?
First, npm checks your local machine for packages installed globally, or using the -g flag.
ie: if you used npm install -g moduleName
You can run npm list -g to figure out where that is on your machine.
Otherwise, npm goes to where you set the npm registry. By default this is npmjs.
If you want to see the default settings, run npm config list

NPM Install is not installing dependencies

I'm attempting to install the Ushahidi V3 Client. I've been following the install process up until when I need to build the project from the source repo using npm and gulp - both of which I've had zero experience with. Whenever I run sudo npm install in the project directory, the process runs without complaints. However, when I run npm ls to verify that dependencies have been downloaded, I get a bunch of dependencies listed out as being missing.
How do I get npm to resolve all of these dependencies?
System Details
OS Ubuntu 14.04 (Trusty)
Node JS v0.12.9
NPM v3.5.1
What I've tried
Removing node_modules folder and re-running sudo npm install as referenced in this SO answer for a similar question: npm Gulp dependencies missing, even after running npm install
Uninstalling and reinstalling node and npm
#Strainy, as your research :D
It was a combination of running as sudo and not having the build-essentials.
That's why you should not use sudo npm
Follow these steps:
try npm uninstall. and then try npm install.
Also If it still doesn't work.
Try:
npm install -g npm-install-missing
or
npm-install-missing
For further reading, click here.

How to tell what’s installed under npm

I just want to get a snapshot of what's installed locally in a project and what's installed globally:
npm whats-installed-locally
npm whats-installed-globally
npm whats-dependencies-between-local-global-repos
What's the proper command-line sequence?
Also, is there a way to determine which dependencies are being unhinged between the two repositories?
To list the local installed npm packages:
npm list
To list the globally installed npm packages:
npm list -g

Resources