Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NODE_PATH is being ignored or not working

Tags:

node.js

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).

  • added export NODE_PATH=/development/nodeproject to my ~/.bash_profile
  • ran source ~/.bash_profile
  • if I run env I see NODE_PATH=/development/nodeproject listed there
  • in my app.js if I console log process.env.NODE_PATH I get /development/framework (should this output an array instead of a string?)

Other information that might be relevant:

  • I'm on node v0.6.7
  • I'm doing all of this as root (sudo su -)

At this point I'm not sure what else I can do. Any help would be greatly appreciated.

like image 405
JWK Avatar asked Jan 21 '12 17:01

JWK


2 Answers

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

like image 179
intern Avatar answered Nov 12 '22 22:11

intern


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

like image 35
Clueless Avatar answered Nov 12 '22 23:11

Clueless