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


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 -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)
Problem courtesy of: B T


there was an issue filed on the npm-github repository requesting that feature.

read on here:

Solution courtesy of: hereandnow78


You could do this:

  1. Get the tarball and extract it
  2. Change the name in its package.json to @me/mymoduleTemp (you could skip steps 1 and 3 by editing the tarball in place with vim mymoduleTemp.tgz)
  3. Compress it to mymoduleTemp.tgz
  4. Run npm publish mymoduleTemp.tgz (with --access public unless you want it to be restricted)
  5. In your main project, run npm install @me/mymoduleTemp

I'd recommend publishing it as a scoped package, because if you publish it as unscoped mymoduleTemp, then no one else can use that name.

If you think even publishing scoped packages is polluting the npm registry, then you can just put the new tarball on your own private server (or in GitHub, or wherever) and install it via URL.

Discussion courtesy of: Andy

This recipe can be found in it's original form on Stack Over Flow.