使用Node.js尝试获取以下网页的html内容时:
eternagame.wikia.com/wiki/EteRNA_Dictionary
我收到以下错误:
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Run Code Online (Sandbox Code Playgroud)
我确实已经在stackoverflow上查找了这个错误,并意识到这是因为node.js无法从DNS中找到服务器(我认为).但是,我不确定为什么会这样,因为我的代码完美无缺www.google.com.
这是我的代码(几乎从一个非常相似的问题复制和粘贴,除了更改主机):
var http = require("http");
var options = {
host: 'eternagame.wikia.com/wiki/EteRNA_Dictionary'
};
http.get(options, function (http_res) {
// initialize the container for our data
var data = "";
// this event fires many times, each time collecting another piece of the response
http_res.on("data", function (chunk) {
// append this chunk to our growing `data` var
data …Run Code Online (Sandbox Code Playgroud) 我对node.js有另一个问题,这次我无法获取我的javascript代码来识别coffeescript模块的类有功能.
在我的主文件main.js中,我有以下代码:
require('./node_modules/coffee-script/lib/coffee-script/coffee-script');
var Utils = require('./test');
console.log(typeof Utils);
console.log(Utils);
console.log(typeof Utils.myFunction);
Run Code Online (Sandbox Code Playgroud)
在我的模块test.coffe中,我有以下代码:
class MyModule
myFunction : () ->
console.log("debugging hello world!")
module.exports = MyModule
Run Code Online (Sandbox Code Playgroud)
这是我运行时的输出node main.js:
function
[Function: MyModule]
undefined
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么我的主文件加载了正确的模块,但为什么它无法访问该函数?我做错了什么,无论是使用coffeescript语法,还是我需要我的模块?如果我应该澄清我的问题,请告诉我.
谢谢,
维尼特