找不到 node.js 模块

cannot find node.js module

我按照 nodejs 书 node.js 以正确的方式进行操作,但在尝试执行此命令时卡住了。我将 #!/usr/bin/env 更改为 #!/usr/bin/node 因为 env 对我来说甚至不是一个文件夹,我相信 node.js 在节点文件夹中。我 运行 ubuntu 14.04。有什么办法?如果重要的话,我在后台有 couchdb 运行。谢谢

ryan@Ryan:~/Documents/code/databases$ ./dbcli.js

module.js:340
    throw err;
          ^
Error: Cannot find module '/home/ryan/Documents/code/databases/node --harmony'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

这是程序

#!/usr/bin/node node --harmony
/***
 * Excerpted from "Node.js the Right Way",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/jwnode for more book information.
***/
const
  request = require('request'),
  options = {
    method: process.argv[2] || 'GET',
    url: 'http://localhost:5984/' + (process.argv[3] || '')
  };
request(options, function(err, res, body) {
  if (err) {
    throw Error(err);
  } else {
    console.log(res.statusCode, JSON.parse(body));
  }
});

由于我的评论解决了您的问题,所以将其作为答案:

我最后检查过,您不能将 #!/usr/bin/node node --harmony 放入传递给节点的 .js 文件中,因为它无效 Javascript。您可以手动删除该行和 运行 .js 文件,只需键入以下内容:

node --harmony dbcli.js

仅供参考,看起来可以做你想做的事,但你没有使用正确的语法,因为你试图 运行 node node。参见 this answer

shebang 行应该是

#!/usr/bin/node --harmony

在当前行中,您告诉节点 运行 名为 "node" 的模块。