How to install a node.js module without using npm?

node.jsPackagesNpm

node.js Problem Overview


There are quite a few modules which are listed https://github.com/joyent/node/wiki/modules">on node's github page but are not published with the npm-registry. These modules can't be installed using npm.

What is the correct way to install these nodejs modules after cloning them from Git?

node.js Solutions


Solution 1 - node.js

You need to download their source from the github. Find the main file and then include it in your main file.

An example of this can be found here > https://stackoverflow.com/questions/5778474/uploaing-file-in-node-js/5780829#5780829

Usually you need to find the source and go through the package.json file. There you can find which is the main file. So that you can include that in your application.

To include example.js in your app. Copy it in your application folder and append this on the top of your main js file.

var moduleName = require("path/to/example.js")

Solution 2 - node.js

> These modules can't be installed using npm.

Actually you can install a module by specifying instead of a name a local path. As long as the repository has a valid package.json file it should work.


Type npm -l and a pretty help will appear like so :

CLI:

...
install     npm install <tarball file>
                npm install <tarball url>
                npm install <folder>
                npm install <pkg>
                npm install <pkg>@<tag>
                npm install <pkg>@<version>
                npm install <pkg>@<version range>
                
                Can specify one or more: npm install ./foo.tgz bar@stable /some/folder
                If no argument is supplied and ./npm-shrinkwrap.json is 
                present, installs dependencies specified in the shrinkwrap.
                Otherwise, installs dependencies from ./package.json.

What caught my eyes was: npm install <folder>

In my case I had trouble with mrt module so I did this (in a temporary directory)

  • Clone the repo

       git clone https://github.com/oortcloud/meteorite.git
    
  • And I install it globally with:

       npm install -g ./meteorite
    

Tip:

One can also install in the same manner the repo to a local npm project with:

     npm install ../meteorite

And also one can create a link to the repo, in case a patch in development is needed:

     npm link ../meteorite

Edit:

Nowadays npm supports also github and git repositories (see https://docs.npmjs.com/cli/v6/commands/npm-install), as a shorthand you can run :

npm i github.com:some-user/some-repo

Solution 3 - node.js

Download the code from github into the node_modules directory

var moduleName = require("<name of directory>")

that should do it.

if the module has dependancies and has a package.json, open the module and enter npm install.

Hope this helps

Solution 4 - node.js

You can clone the module directly in to your local project.

Start terminal. cd in to your project and then:

npm install https://github.com/repo/npm_module.git --save

Solution 5 - node.js

Step-by-step:

  • let's say you are working on a project use-gulp which uses(requires) node_modules like gulp and gulp-util.

  • Now you want to make some modifications to gulp-util lib and test it locally with your use-gulp project...

  • Fork gulp-util project on github\bitbucket etc.

  • Switch to your project: cd use-gulp/node_modules

  • Clone gulp-util as gulp-util-dev : git clone https://.../gulp-util.git gulp-util-dev

  • Run npm install to ensure dependencies of gulp-util-dev are available.

  • Now you have a mirror of gulp-util as gulp-util-dev. In your use-gulp project, you can now replace: require('gulp-util')...; call with : require('gulp-util-dev') to test your changes you made to gulp-util-dev

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionvivekian2View Question on Stackoverflow
Solution 1 - node.jsneebzView Answer on Stackoverflow
Solution 2 - node.jsTiberiu C.View Answer on Stackoverflow
Solution 3 - node.jsiancrowtherView Answer on Stackoverflow
Solution 4 - node.jsMolnfrontView Answer on Stackoverflow
Solution 5 - node.jsVikramView Answer on Stackoverflow