How to specify the path to "package.json" when running npm install?

For a new project I am working on, I want to install my node packages in one directory while having my "packages.json" file in another. In other words, I want to have my "node_modules" directory and "packages.json" file in two separate folders. Is there a way to do this? I have looked through the command documentary, but can't seem to find a solution.

1 answer

  • answered 2018-01-11 19:43 vitaly-t

    It is quite simple...

    You create a separate package.json in every folder where you want node_modules in the same folder. That's how NPM works ;)

    You can have any number of package.json files in your project.

    Other than that, you cannot separate node_modules from package.json, because Node.js uses package.json to look for the right modules that you include with require. For example, when running npm update in that folder, you need both pieces in the same folder.

    And that's how NPM and Node.js work happily together ;)