Reputation: 4797
Is there a way to install and also use the different package versions in npm
? Installations works:
npm install -g packagename@2.8
npm install -g packagename@3.1
npm install -g packagename@4.0
I can install npm install -g web3@0.20.7
and check npm view web3 versions
them. But how can I use them in the *.js
script? Something like this:
require('packagename@2.8');
require('packagename@3.1');
require('packagename@4.0');
Upvotes: 5
Views: 1824
Reputation: 25755
I did some research and it seems that its not possible with standard NPM. Here is the feature-request: https://github.com/npm/npm/issues/5499
However, with yarn
(an NPM alternative from Facebook), you can do it out of the box by using yarn add
and giving the package an alias.
I have not tried this for globally installed packages though, I assume it works the same.
Upvotes: 2
Reputation: 568
There is a node module that allows you to do it.
npm-install-version
Install it: npm install npm-install-version --save-dev
var niv = require('npm-install-version');
niv.install('packagenameolder@1.0.0');
niv.install('packagenamenewer@1.0.1');
var package_old = niv.require('packagenameolder@1.0.0');
var package_new = niv.require('packagenamenewer@1.0.1');
Upvotes: 2