#StackBounty: #npm Tell NPM to install in different directory

Bounty: 50

I have a situation where due to the requirements/opinion of a project I’m working with, I have to keep my package.json file in a nested directory. See below:

/my-app
  |-- /functions
    |-- /node_modules
    |-- package.json

The problem I have run into several times now is that I run npm i <package> from within /my-app and not /my-app/functions without realizing it and I end up spending time unnecessary time debugging my app because I installed the package in the wrong place.

Is there a way to create a root-level package.json file that merely tells NPM, “hey, if you’re going to install something, do it in this other directory.”? For example:

/my-app
  |-- package.json <-- add this
  |-- /functions
    |-- /node_modules
    |-- package.json

And maybe the package.json file within the root directory would look something like this?

{
  "installDirectory": "/functions"
}

This functionality may already exist, but I was unable to find it in the documentation. The --prefix flag is similar, but it doesn’t automatically handle the case I’m describing.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.