Bug 1006531

Summary: node can't find requires without NODE_PATH
Product: [Fedora] Fedora Reporter: Fabian Deutsch <fabian.deutsch>
Component: nodejsAssignee: T.C. Hollingsworth <tchollingsworth>
Status: CLOSED WONTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 19CC: fdeutsch, jamielinux, mrunge, sgallagh, tchollingsworth, thrcka
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-09-10 23:01:41 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Fabian Deutsch 2013-09-10 18:51:17 UTC
Description of problem:
I need to call
NODE_PATH=/usr/lib/node_modules node file.js
otherwise (without NODE_PATH) node won't find the required modules.

Comment 1 T.C. Hollingsworth 2013-09-10 23:01:41 UTC
This is by design.

Node.js' global module search path is by default set only to './node_modules', to allow the developer to create separate directories with separate dependency chains, similar to how virtualenv works with Python.  To use yum-installed dependencies, just `npm link` them into your local project.  To use dependencies we don't have yet, just `npm install` them.

For instance:

% mkdir test

% cd test

% cat >test.js <<EOF
> var request = require('request')
> request('https://badges.fedoraproject.org/user/fabiand/json', function (error, response, body) {
>  if (!error && response.statusCode == 200) {
>    var num = JSON.parse(body).assertions.length
>    console.log('You have ' + num + ' badges!')
>  }
> })
> EOF

% node test.js
Error: Cannot find module 'request'

% npm link request

% node test.js
You have 20 badges!

For more information on the rationale behind this, see the npm FAQ:
https://npmjs.org/doc/faq.html#I-installed-something-globally-but-I-can-t-require-it

Comment 2 Fabian Deutsch 2013-09-11 07:34:46 UTC
Thanks for this explanation.