sunwarr10r
sunwarr10r

Reputation: 4797

npm: install and use different versions of a package

Is there a way to install and also use the different package versions in npm? Installations works:

npm install -g [email protected]
npm install -g [email protected]
npm install -g [email protected]

I can install npm install -g [email protected] and check npm view web3 versions them. But how can I use them in the *.js script? Something like this:

require('[email protected]');
require('[email protected]');
require('[email protected]'); 

Upvotes: 5

Views: 1824

Answers (2)

Lukas Knuth
Lukas Knuth

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

Sagar Rana
Sagar Rana

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('[email protected]');
niv.install('[email protected]');

var package_old = niv.require('[email protected]');
var package_new = niv.require('[email protected]');

Upvotes: 2

Related Questions