繁体   English   中英

找不到node.js模块

[英]cannot find node.js module

我跟着nodejs一起以正确的方式跟随着node.js,并且在尝试执行此命令时卡住了。 我将#!/ usr / bin / env更改为#!/ usr / bin / node,因为env甚至不是我的文件夹,而node.js在我相信的节点文件夹中。 我正在运行Ubuntu 14.04。 解决办法是什么? 如果有关系,我可以在后台运行ouchdb。 谢谢

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));
  }
});

因为它解决了您的问题,所以使我的评论成为答案:

最后我检查了一下,因为您的Java脚本无效,所以您无法将#!/usr/bin/node node --harmony node --harmony放在传递给节点的.js文件中。 您可以删除该行并通过键入以下命令手动运行.js文件:

node --harmony dbcli.js

仅供参考,看起来可能可以执行您尝试做的事情,但是由于尝试运行node node ,因此未使用正确的语法。 看到这个答案

社bang线应该是

#!/usr/bin/node --harmony

在当前行中,您要告诉节点运行名为“节点”的模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM