NODE_PATH is ignored or not working

I am trying to run my node application on a new server, and I have some problems with the NODE_PATH environment variable. The application works fine on my local machine (OSX Lion), but not on the server (Redhat linux). When I launch my application with node app.js from 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 application and looks like this: var Category = require('mod/core/models/Category') . Thus, it is obvious that node is not looking for modules in my project directory.

I'm not sure why, though, because I made the following changes (which work 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 specified there
  • in my app.js, if I have a console log process.env.NODE_PATH I get /development/framework (should this output an array instead of a string?)

Other information that may be relevant:

  • I am node v0.6.7
  • I do it all as root (sudo su -)

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

+4
source share
2 answers

NODE_PATH is used for modules, not decision files. Try module.paths.push ("/ development / nodeproject", "one / more / path"); before calling require (). And you really should use a relative query, e.g. require ('./mod/core/models/Category') for files in the nodeproject directory

+5
source

The functionality you are looking for has been removed. Use the node_modules directory or relative query, e.g. require('./mod/core/models/Category') .

There is additional information in this answer: NODE_PATH error with node.js when trying to configure jsctags for vim

+2
source

Source: https://habr.com/ru/post/1392229/


All Articles