I'm new to Node but am enjoying myself so far. I was trying to move my node_modules
(libraries) directory outside of the public 'webroot' and need advice and guidance.
I've setup my simple expressJS based Node project as follows:
/my_project
/config
/public
/node_modules
server.js
I was wondering if there was any way I could have the /node_modules
dir outside of my webroot and not break my application. I'm just so used to keeping the bare minimum in my publicly exposed webroot and don't feel right with the libs being in there. Call me old fashioned but that's how I'm used to doing stuff in the PHP and C# world.
If I setup the project as follows:
/my_project
/config
/node_modules
/public
server.js
then it all goes wobbly and Node's require()
magic breaks.
I've tried the following:
var express=require('../express');
which doesn't work either giving me the 'Cannot Find module' type error.
- Is what I'm asking even possible, if so then how?
- Are there any major risks with me having my libs in a webroot or have I missed something fundamental here with the way Node works.
What do you guys do, what is best practice for production apps?May I have some examples of your production practices and why.