node.js:为什么NODE_DEBUG = 1不起作用? (试图debugging一个require()错误)

我有一个像这样的目录结构:

project lib paperboy redis-client node-cookie srv main.js ... 

我从项目目录中启动main.js:

 $ node srv/main.js 

在main.js中,我可以这样做:

  paperboy = require('./lib/paperboy'); 

但是,这失败了:

  redis = require('./lib/redis-client'); 

同样,如果我在“项目”目录中启动交互式节点,我可以要求paperboy,而不是redis-client。 我得到的错误是:

 > require('./lib/redis-client') Error: Cannot find module './lib/redis-client' at resolveModuleFilename (node.js:265:13) at loadModule (node.js:231:20) at require (node.js:291:14) ... 

查看resolveModuleFilename()的源代码,它试图打印一个debuggingstring,我没有看到:

 debug("looking for " + JSON.stringify(id) + " in " + JSON.stringify(paths)); 

我已经尝试通过导出NODE_DEBUG = 1来启用它,但是在尝试请求时仍然看不到此debugging打印。

我在做什么错误试图让这个debugging打印? 其次,为什么paperboy加载正常,但redis-client无法find?

附加信息:以下是“lib”目录中的完整文件/目录列表:

 lib lib/cookie-node lib/cookie-node/package.json lib/cookie-node/LICENSE.txt lib/cookie-node/README.markdown lib/cookie-node/example lib/cookie-node/example/ex1.js lib/cookie-node/index.js lib/redis-client lib/redis-client/package.json lib/redis-client/TODO.md lib/redis-client/examples lib/redis-client/examples/redis-version.js lib/redis-client/examples/using-kiwi.js lib/redis-client/examples/subscriber.js lib/redis-client/examples/publisher.js lib/redis-client/examples/.redis-version.js.swp lib/redis-client/examples/README.md lib/redis-client/seed.yml lib/redis-client/LICENSE lib/redis-client/test lib/redis-client/test/test_throw_from_callback.js lib/redis-client/test/test_shutdown_reconnect.js lib/redis-client/test/test.js lib/redis-client/test/sample.png lib/redis-client/.gitignore lib/redis-client/lib lib/redis-client/lib/redis-client.js lib/redis-client/README.md lib/paperboy lib/paperboy/package.json lib/paperboy/seed.yml lib/paperboy/LICENSE.txt lib/paperboy/example lib/paperboy/example/basic.js lib/paperboy/example/webroot lib/paperboy/example/webroot/img lib/paperboy/example/webroot/img/paperboy.jpg lib/paperboy/example/webroot/index.html lib/paperboy/index.js lib/paperboy/lib lib/paperboy/lib/paperboy.js lib/paperboy/README.md 

lib目录是从github解压缩的.tar.gz文件,重新命名以匹配来自package.json文件的模块名称。

  1. Node.js查找相对于脚本位置的所需文件,所以你应该使用

    paperboy = require('../ lib / paperboy');

    在srv / mail.js。

  2. 你必须用–debug选项来保证node.js,然后让它使用任何debuggingfunction,据我所知。

你想导出NODE_DEBUG=module ,不是=1

这是不工作的原因是因为Node.js会自动包含一个脚本,如果它有名字index.js

Node Cookie和Paperboy看起来像这样:

 lib/cookie-node/index.js lib/paperboy/index.js 

Redis Client看起来像这样:

 lib/redis-client/lib/redis-client.js 

您需要将您的要求更改为:

 var redis = require('./lib/redis-client/lib/redis-client'); 

本质上,节点查找require文件,如下所示:

 var redis = require('./lib/redis-client'); ./lib/redis-client.js ./lib/redis-client/index.js // (if redis-client is a directory). 

由于没有index.js文件,节点无法继续查看./lib/redis-client/的lib目录,也不会包含该文件,因为它不知道它被调用的内容或应该在哪里位于。