Question: I'm working on a CLI tool in NodeJS that uses another NodeJs package that we develop, which is an SDK. 

The thing is, we just published a V2 version of that SDK, and we want to offer the CLI user a legacy mode, so they can use either the first or second version of our SDK, like so:

```
$ cli do-stuff
#execute sdk v2

```

Or

```
$ LEGACY_MODE='on' cli do-stuff
#execute sdk v1

```

My problem is that I did not found any clean way to use two versions of the same dependency in my CLI.
I tried to use [npm-install-version](https://www.npmjs.com/package/npm-install-version) package. It works well on my local environment, but after publishing my cli and doing `npm install -g my-cli`, it doesn't work anymore, because it creates a node\_modules folder in the current folder, instead of the `/usr/local/lib/node_modules/my-cli` folder.
I also tried [multidep](https://www.npmjs.com/package/multidep), and I have kind of the same issue.

For now, my package.json do not contain at all my sdk, but I would like to have something like :

```
"dependencies": {
  "my-sdk": "2.0.0"
  "my-sdk-legacy": "1.0.0"
}

```

Or

```
"dependencies": {
  "my-sdk": ["2.0.0", "1.0.0"]
}

```

I haven't found anything else yet. I'm thinking about publishing the first version of my sdk package with another name, like "my-sdk-legacy", but I would like to avoid that if possible.

Any solution for that ?

Answer: 
*Based on [my answer for a similar question:](https://stackoverflow.com/a/56495651/7770056)*

As of [npm v6.9.0,](https://github.com/npm/cli/releases/tag/v6.9.0) npm now supports package aliases. It [implements the same syntax](https://github.com/npm/rfcs/blob/latest/implemented/0001-package-aliases.md#detailed-explanation) as Yarn uses:

```
npm install my-sdk-legacy@npm:my-sdk@1
npm install my-sdk

```

This adds the following to `package.json`:

```
"dependencies": {
  "my-sdk-legacy": "npm:my-sdk@^1.0.0",
  "my-sdk": "2.0.0"
}

```

This seems to me the most elegant solution available, and is compatible with the [Yarn solution proposed by @Aivus.](https://stackoverflow.com/questions/43770328/two-versions-of-same-npm-package-in-node-application/52311693#52311693)
I needed to run two versions of [tfjs-core](https://github.com/tensorflow/tfjs-core) and found that both needed to be built after being installed.

package.json:

```
"dependencies": {
  "tfjs-core-0.14.3": "git://github.com/tensorflow/tfjs-core#bb0a830b3bda1461327f083ceb3f889117209db2",
  "tfjs-core-1.1.0": "git://github.com/tensorflow/tfjs-core#220660ed8b9a252f9d0847a4f4e3c76ba5188669"
}

```

Then:

```
cd node_modules/tfjs-core-0.14.3 && yarn install && yarn build-npm && cd ../../
cd node_modules/tfjs-core-1.1.0  && yarn install && yarn build-npm && cd ../../

```

And finally, to use the libraries:

```
import * as tf0143 from '../node_modules/tfjs-core-0.14.3/dist/tf-core.min.js';
import * as tf110  from '../node_modules/tfjs-core-1.1.0/dist/tf-core.min.js';

```