Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install a package with npm with a different/custom module name

Tags:

I want to install a specific revision from a github tarball named something like "mymodule" and name it something like "mymoduleTemp", and then load a potentially different version of it that will take the real name "mymodule".

So, how do I do the first thing? I'm looking for something like:

npm install https://github.com/me/mymodule/tarball/someTag -name mymoduleTemp 

Is there any way to do that? A nice-to-have:

  • If mymodule already exists, it doesn't get clobbered when mymoduleTemp is installed (ie ideally the process wouldn't be to install as mymodule then rename the folder)
like image 750
B T Avatar asked Jun 15 '13 19:06

B T


People also ask

How do I install a specific node module?

Use npm list [package-name] to know the specific latest version of an installed package. Use npm install [package-name]@[version-number] to install an older version of a package. Prefix a version number with a caret (^) or a tilde (~) to specify to install the latest minor or patch version, respectively.


2 Answers

Since [email protected] you could install package under a custom module name. [email protected] introduces support for package aliases.

To install a tarball under custom module name use custom-name@tarball-url argument, e.g. install specific express tarball as my-express module:

npm i my-express@https://github.com/expressjs/express/archive/4.16.3.tar.gz

This feature also allows to alias packages published to npm registry:

npm i express@npm:@my-scope/express

like image 177
Pavel Zubkou Avatar answered Sep 21 '22 00:09

Pavel Zubkou


In newer versions of npm (6+), its now possible to alias the module name with

npm i <alias_name>@npm:<original_package_name> 
like image 38
Efrat Levitan Avatar answered Sep 22 '22 00:09

Efrat Levitan