1

I have an app using the file structure

package.json
src/main/
 - webapp
 - java (containing my API)

My API is restricted so that it can only dispatch files from within src/main/webapp, as a result I need my node_modules to install within that folder.

If I run npm install I get the following:

package.json
node_modules/
src/main/
 - webapp
 - java (containing my API)

Is there a way I can change this so it installs by default in the following structure?

package.json
src/main/
 - webapp
    - node_modules/
 - java (containing my API)

If possible I'd rather not have a global environment variable as I work on multiple apps on this machine and I don't want them all installing to this apps node_modules

Eduardo
  • 6,900
  • 17
  • 77
  • 121
  • Possible duplicate of [Specify path to node\_modules in package.json](http://stackoverflow.com/questions/26293049/specify-path-to-node-modules-in-package-json) – Josh C. Jan 28 '16 at 18:45
  • Also http://stackoverflow.com/questions/14742553/npm-local-install-package-to-custom-location – Josh C. Jan 28 '16 at 18:47
  • Why do you care where the dependencies are? As long as the runtime finds and loads them, you shouldn't worry about it. – Amit Jan 28 '16 at 18:48
  • @Amit My server needs to be able to dispatch them which is only possible from within src/main/webapp – Eduardo Jan 28 '16 at 18:51
  • @Amit for example if I was to have a dependency on Angular (which I would need in my index.html dependencies) then that would need to be dispatchable by my server, hence it would need to be in src/main/webapp – Eduardo Jan 28 '16 at 18:52
  • By "*dispatch*" do you mean *serve* (as in "web server")? – Amit Jan 28 '16 at 18:53
  • @Amit I do indeed :) – Eduardo Jan 28 '16 at 18:55
  • @JoshC. Using an environment variable like those answers suggest would surely mean by other apps would pick it up as well wouldnt it? I would like all my apps to be self contained if possible – Eduardo Jan 28 '16 at 18:56
  • And you're using paths that include "/node_modules/angular/..." to do that? That's not the way you should do things – Amit Jan 28 '16 at 18:57
  • @Amit what alternative is there? This is what https://www.npmjs.com/package/angular seems to be suggesting – Eduardo Jan 28 '16 at 18:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/101924/discussion-between-amit-and-ed0906). – Amit Jan 28 '16 at 18:59

1 Answers1

0

For the case above I intended to install my webapp dependencies, such as AngularJS using NodeJS. It turns out there is another package manager Bower that is much more fit for this purpose and allows you to configure the location of its bower_componentsto wherever you like. This has solved my issue and I now have the following file structure

package.json
node_modules/
src/main/
 - webapp
    -bower_components
        -angular (etc) 
 - java (containing my API)
Eduardo
  • 6,900
  • 17
  • 77
  • 121