5

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]'); 
0

2 Answers 2

2

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]'); 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, this looks useful, but the last update was 2 years ago. Is this still the way to go and also compatible with the new node/npm versions?
I am not sure about compatible with latest npm version. You can go for yarn if you want.
like==> yarn add alias-for-package@npm:packagename@version
2

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.