NODE_PATH is being ignored or not working - 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.

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

Related

Node JS error: Cannot find module '../build/jvm_dll_path.json'

I am receiving the following error after running npm start:
Error: Cannot find module '../build/jvm_dll_path.json'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/opt/stature-gqdss/node_modules/java/lib
[nodemon] app crashed - waiting for file changes before starting...
Can you help me with this issue?
First, you should check if the server is already running and kill the existing server. If no other server is running, try reinstalling your dependencies and try again.
npm install
I have a hack here. You can simply create a file named jvm_dll_path.json inside node_modules\java\build and paste the path of server to this, between quotes like shown below..
";C:\\Program Files\\Java\\jdkX.X.X_XXX\\jre\\bin\\server"
For me running
node postInstall.js
in the node_modules/java folder worked.

Change node path to current directory

I was trying to run this command from my user directory
NODE_ENV=~/Public/project node socket.js
But it return this error
Error: Cannot find module '/home/user/socket.js'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:418:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:533:3
The thing is i do not want to change directory. Is it possible to do that? And why this is happening?
NODE_ENV is, by convention, the type of environment you're running in, e.g. Development or Production or Test. It only matters for modules that inspect it and set options accordingly, e.g. Many loggers will default to more verbose in development.
Not really sure why you wouldn't just change directories, but your call to server.js can be an absolute or relative path. If the file is in the /home/user/project folder, you can (from /home/User) just call
node ./project/socket.js
After a little mor research, i found this
And according to that site, i have to do this
export NODE_CONFIG_DIR=/home/user/Public/project/config
and run this
node ./Public/smart-backwall-server/socket.js

Mongoose on c9 how to fix

I didn't close my mongod when closing the laptop and now its giving me an error. On top of that, I delete the mongod data directory with all my data in it. Now I can start up my apps using node js - is there anyway to fix this or do I need to redo all my app.js again?
Error: Cannot find module '/home/ubuntu/workspace/RESTful/RESTful
Routing/RESTfulBlogApp/cats.js'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
All the files which are required in your node app must be present at the time of execution.
As per the error, it is unable to find cat.js in the required folder. You need to create again all the required files, and if they were your dbSchema, i would suggest you create your schemas again before running the app.

slimerjs Can not resolve required module encoding

I have seen slimerjs Can not resolve required module, works with phantomjs, but that one explains absolutely nothing, so I'll dare ask the question again.
I have done this:
$ npm install -g encoding
encoding#0.1.12 /home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/encoding
└── iconv-lite#0.4.13
So, apparently, it should be there?
Now, I'm trying this test script, as stated in https://www.npmjs.com/package/encoding - let's call it test_modload.js:
var encoding = require('encoding');
... and I try to run it with node:
$ node test_modload.js
module.js:338
throw err;
^
Error: Cannot find module 'encoding'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/path/to/test/test_modload.js:1:78)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
Apparently, here I have to use NODE_PATH:
NODE_PATH=/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules node test_modload.js
... and this command passes fine (i.e. returns nothing, and prints no errors).
But what if we try this with casperjs? The script becomes:
var encoding = require('encoding');
var casper = require('casper').create();
casper.run();
... and if I run with:
/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/casperjs test_modload.js
... again all is fine (i.e. returns nothing, and prints no errors).
But let's try this with casperjs with slimerjs engine:
$ SLIMERJSLAUNCHER=/usr/bin/firefox46 /home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/casperjs --engine=slimerjs test_modload.js
Script Error: Module: Can not resolve "encoding" module required by main located at file:///home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/bootstrap.js
Stack:
-> file:///home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/bootstrap.js: 350
Eh... I guess NODE_PATH is missing?
$ NODE_PATH=/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules SLIMERJSLAUNCHER=/usr/bin/firefox46 /home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/casperjs --engine=slimerjs test_modload.js
Script Error: Module: Can not resolve "encoding" module required by main located at file:///home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/bootstrap.js
Stack:
-> file:///home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/bootstrap.js: 350
Damn it, I ran out of options. What do I do now, how can I get encoding to work with slimerjs? Note that the slimerjs docs state in https://docs.slimerjs.org/current/api/require.html that one should use require.paths, however, for node standalone, it would complain with:
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
... while slimerjs doesn't output this error; but still, no change if I do require.paths.push('/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules'); - it still 'can not resolve "encoding" module'.
Just to make sure I have the right path, here is a listing:
$ ls /home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules
casperjs encoding npm utf8 zombie
$ ls /home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/encoding/
lib LICENSE node_modules package.json README.md test
... so apparently the module is there.
So, how on earth can I get slimerjs to find and use the encoding module in a script?

Parse-Server Local Installation — external modules

I installed with success a Parse-Server on my local machine from this GUID.
I tried first with global installation, then I tried to understand better (It's the first time I see something related to Node.js) and I installed in a local directory. I think it should be the same.
this is what I done:
npm install parse-server parse-dashboard underscore
this is how the directory looks like:
/parse: ls
dashboard-config.json
logs
node_modules
ls node_modules/underscore
LICENSE
README.md
package.json
underscore-min.js
underscore-min.map
underscore.js
ls node_modules/parse
parse/
parse-dashboard/
parse-json/
parse-server/
parseurl/
Next I try to include also the cloud code I developed. the main.js has this content:
//var Image = require("parse-image");
var _ = require('underscore');
...
This is how I started the server:
node_modules/parse-server/bin/parse-server \
--appId APPID --masterKey MASTERKEY \
--databaseURI mongodb://localhost:27017/MyAPP \
--cloud /absolutepathfor/MyApp/cloud/main.js
and the error I got
module.js:341
throw err;
^
Error: Cannot find module 'underscore'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/Users/......./main.js:2:9)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
How can I include in this case underscore, but in any case other libraries?
[update]
I installed globally the underscore lib (node install -g underscore).
I create a symbolic link cloud -> < path where is located cloud/main.js >
Next I created package.json with npm init command
I launch again npm install
I created app.js like described in the guid and I configured it using the same parameters above.
I started the server with node app.js
all gone fine. the problem right now is in permissions on create a new document, where I should already have that grants, but this will be another problem to solve. I hope this can help somebody else
I hit the same problem and error message. I did the followings and it works
npm install underscore
use this path:
var _ = require('../node_modules/underscore/underscore.js')
Refer to more details in this post.
Can't get 'underscore' to work with parse server
I just sorted a similar issue while transferring Parse.com CloudCode to a self hosted Parse Server on Nodejs; in one of the controller we had the line
var _ = require('underscore.js');
It had to be done like this on Parse.com. But now as we are on NodeJS and have NPM—it's enough to just do:
var _ = require('underscore');
(ie: drop the .js extension)

Resources