Installing different versions of the same package using NPM

sujesh thekkepatt
2 min readSep 9, 2021

--

In this small article, we are going to experiment with how we can install two versions of the same package using NPM.

Why do we want different versions of the same packages? Consider this scenario where you want to experiment with the different versions of the same package or you want to incrementally update the new packages. Whatever the case may be knowing this little tweak always comes in handy.

Well, how do we do it ? Using npm you can install packages under an alias. That means you can install the different versions of the same package under an alias using NPM. And this feature landed in NPM from v6.9.0onwards. If you haven’t updated the NPM version till now please do update it.

Now let’s see how we can install different versions. I want to install a promise-based version and legacy version of a popular npm package called redis . The promise-based version is called redis@next and the callback version is called redis .

npm i alias@npm:actual_package@version this command will help you to install the package in a separate alias and you can use this alias when requiring from the package. No conflict or whatsoever.

So having this in mind let’s install the redis@nextversion on a different alias.

npm i redis-next@npm:redis@next and npm i redis . Now we installed both versions. To check it out head over to your package.json and you can see the packages there. One with the alias name ie redis-nextand the other with a name as redis.

The same can be used to install different versions of the same package. Thus you can incrementally update your API changes. Happy coding :)

Hi, I am Sujesh. I occasionally write things I find useful. If you like my work and want to support it, buy me a cup of coffee!. Thanks.

--

--