I'm trying to run my node app on a new server and am having some issues with the NODE_PATH environment variable. The app works fine on my local machine (OSX Lion) but not on the server (Redhat linux). When starting my app with node app.js
from within my project directory /development/nodeproject
, I get the following error :
Error: Cannot find module 'mod/core/models/Category'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at /development/nodeproject/app.js:57:5
at Object.<anonymous> (/development/nodeproject/app.js:258:1)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
mod/core/models/Category
is the first require() in my app.js and looks like this: var Category = require('mod/core/models/Category')
. So apparently node is not looking for modules in my project directory.
I'm not sure why though, because I made the following changes (that are working just fine on my local machine).
export NODE_PATH=/development/nodeproject
to my ~/.bash_profilesource ~/.bash_profile
env
I see NODE_PATH=/development/nodeproject
listed thereprocess.env.NODE_PATH
I get /development/framework
(should this output an array instead of a string?)Other information that might be relevant:
At this point I'm not sure what else I can do. Any help would be greatly appreciated.
NODE_PATH used for modules, not for solutions files. Try module.paths.push("/development/nodeproject", "one/more/path"); before any require() call. And you really should use a relative require like require('./mod/core/models/Category') for files in your nodeproject directory
The functionality you are looking for was removed. Use the node_modules
directory or a relative require like require('./mod/core/models/Category')
.
This answer has more info: NODE_PATH error with node.js while attempting to setup jsctags for vim
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With