0

I want to change the node_modules folder default location to this structure:

application
|
|— client
|— server
|  |— node_modules
|  |— package.json
|  |_ ...
|— server.js
|_ ...

I searched about it and found this question at SO and according to the answer node should look for the packages under each sub-folder, but when i run node server it throws an error that says that it can't find the packages. To solve it i use the complete path to the package folder: ./server/node_modules/express, but i would like to only write express

I'm using Node v4.

UPDATE 1

I found a way to do it, but it's a command, so that means that i'll have to run that command when i move the project to the server, or somewhere else?

Here's where i found it.

And this is the command: export NODE_PATH='server'/node_modules

Is there a way to automate the execution of that command?, or a way to define that in a file?

Community
  • 1
  • 1
Jonathan Solorzano
  • 6,812
  • 20
  • 70
  • 131
  • You misunderstand the answer to that question. It doesn't look for the node_modules under each sub-folder in your folder. It looks for the node_modules under each parent-folder in your folder, starting from your folder. INSIDE the node_modules folder it scans for sub-folders to find packages. This means that you should put the node_modules folder in your folder or it's parent folder, not in the sub-folder. Alternatively, you can put server.js in the sub-folder. Trying to do the non-standard thing will make it harder for others to work on your code. – slebetman Sep 17 '15 at 03:39
  • @slebetman oh i see, then how could i create a server.js file at the root folder to point to `server/server.js` and be able to just run `node server` at the root folder? – Jonathan Solorzano Sep 17 '15 at 03:43

0 Answers0