我正在按照正确的方式阅读 Node.js 书籍 Node.js,但在尝试执行此命令时卡住了。我将 #!/usr/bin/env 更改为 #!/usr/bin/node 因为 env 甚至不是我的文件夹,而我相信 node.js 位于 Node 文件夹中。我运行的是 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
and heres the program
#!/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
放入传递给 Node 的 .js 文件中,因为它不是有效的 Javascript。您可以删除该行并手动运行 .js 文件,只需键入以下内容:
node --harmony dbcli.js
仅供引用,看起来可以执行您想要执行的操作,但由于您尝试运行 node Node
,因此您没有使用正确的语法。请参阅this answer .
关于javascript - 找不到node.js模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32150045/