2

Is there a package.json option to specify the relative location of the node_modules directory?

For my application I have a directory structure that looks like the following.

Current Directory Structure

root/
---/client
-------/(client code)
---/server
------/package.json* (sibling of node_modules)
------/node_modules*
------/server.js

I'd like to add grunt tasks to the project's root directory (since they'll apply to both the client code and server code). Gruntfile.js needs to be a sibling of package.json.

I'd like to move package.json to the root directory for this reason, but I'd also like to keep the node_modules within the server directory. Is there an option within package.json to do this?

I'd like the resulting directory structure to look like the following.

Preferred Directory Structure

root/
---/package.json* (not a sibling of node_modules)
---/Gruntfile.js
---/client
-------/(client code)
---/server
------/node_modules*

An option like the following would be the most preferred (there does not seem to be an option like this in the npm docs)

Hypothetical package.json

{
   "output_dir": "server/node_modules", // Something like this
   "dependencies": { ... },
   "devDependencies": { ... }
}
Community
  • 1
  • 1
funseiki
  • 9,167
  • 9
  • 36
  • 59
  • 1
    possible duplicate of [npm local install package to custom location](http://stackoverflow.com/questions/14742553/npm-local-install-package-to-custom-location) – Matthew Bakaitis Mar 17 '14 at 03:07
  • I'm looking for a solution for that as I want to use the same structure for my heroku app. Heroku force you to have the package.json in the root... – darkzangel Jan 11 '15 at 20:29

1 Answers1

3

You can do it with the prefix option on CLI.

npm install express --prefix ./server/node_modules

Don't know similar option exists via package.json

palanik
  • 3,601
  • 1
  • 13
  • 10
  • Hmm, this still requires that my package.json be in the same directory as node_modules. Otherwise I get the error: `"npm ERR! install Couldn't read dependencies"` – funseiki Mar 23 '14 at 18:44