10

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

2
  • 1
    That seems like an ideal situation for using a branch in your source control repository. Commented Dec 12, 2011 at 22:39
  • 1
    the "experimental feature" exists alongside the regular application. It's just that I don't want to force other developers into installing extra dependencies and adding barriers to getting started just for this. Commented Dec 14, 2011 at 0:05

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.