Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use an alternate dependency list for Node.JS + NPM

Is it possible to have two package.json files for a single NodeJS project?

In a project I'm working on, there is an optional and experimental feature which requires some node packages of its own. For every day development, I do not want to force all developers to install those packages.

What I'd like, essentially, is a file which just lists npm dependencies in the a similar format as package.json, and then use npm install to install all of them.

eg:

// package.json:
{
    "dependencies": {
        "underscore": "1.1.7",
        "connect": "1.7.0"
    }
}

// alt.json
{
    "dependencies": {
        "experimental_package": "0.0.1",
        "and_another_one": "1.33.7"
    }
}

And then, something like:

$ npm install
// install the regular package.json stuff
$ npm install alt.json
// install the other ones

Please note that this is not the same as devDependencies

like image 509
nickf Avatar asked Dec 12 '11 18:12

nickf


People also ask

How do I override nested npm dependency versions?

If the nested dependency (with vulnerability) is already fixed but the main dependency isn't, you can use overrides field of package. json as explained in StackOverflow answer. You'll need a recently new version of npm cli v8. 3.0 (2021-12-09) which comes with Node.

How do I use npm dependencies?

To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.


1 Answers

You could make a small script (even in Node.js) so that it executes 'npm install .' twice: one for the original package.json and then for alt.json (package.json gets renamed to _package.json and alt.json gets renamed to package.json; after that's finished rename the files as they were).

I'm not sure about this I've never tried, but I think it could work.

like image 147
alessioalex Avatar answered Sep 18 '22 15:09

alessioalex