Bug 1006531 - node can't find requires without NODE_PATH
node can't find requires without NODE_PATH
Product: Fedora
Classification: Fedora
Component: nodejs (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: T.C. Hollingsworth
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2013-09-10 14:51 EDT by Fabian Deutsch
Modified: 2013-09-11 03:34 EDT (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2013-09-10 19:01:41 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Fabian Deutsch 2013-09-10 14:51:17 EDT
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 19:01:41 EDT
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!')
>  }
> })

% 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:
Comment 2 Fabian Deutsch 2013-09-11 03:34:46 EDT
Thanks for this explanation.

Note You need to log in before you can comment on or make changes to this bug.