Error : getaddrinfo ENOTFOUND in node.js
来源:互联网 发布:synthesia mac 编辑:程序博客网 时间:2024/06/01 21:14
在学习《Node.js In Action》时,第三章Node programming fundamentals中有讲如何处理serial flow的方法,将例子敲到电脑上却发现会报错,例子如下:
var fs = require('fs');var request = require('request');var htmlparser = require('htmlparser');var configFilename = './rss_feeds.txt';function checkForRSSFile () { fs.exists(configFilename, function(exists) { if (!exists) { return next(new Error('Missing RSS file: ' + configFilename)); } console.log(exists); next(null, configFilename); });}function readRSSFile(configFilename) { fs.readFile(configFilename, function(err, feedList) { if (err) return next(err); feedList = feedList .toString() .replace(/^\s+|\s+$/g, '') .split("\n"); var random = Math.floor(Math.random()*feedList.length); console.log(feedList[random]); next(null, feedList[random]); });}function downloadRSSFeed(feedUrl) { request({uri: feedUrl}, function(err, res, body) { if (err) return next(err); if (res.statusCode != 200) { return next(new Error('Abnormal response status code')); } console.log(body); next(null, body); });}function parseRSSFeed (rss) { var handler = new htmlparser.RssHandler(); var parser = new htmlparser.Parser(handler); parser.parseComplete(rss); if (!handler.dom.items.length) { return next(new Error('No RSS items found')); } var item = handler.dom.items.shift(); console.log(item.title); console.log(item.link);}var tasks = [ downloadRSSFeed, parseRSSFeed ];function next(err, result){ if (err) throw err; var currentTask = tasks.shift(); if(currentTask) { currentTask(result); }}next();
它总是会报:
Error: getaddrinfo ENOTFOUND at errnoException (dns.js:37:11) at Object.onanswer [as oncomplete] (dns.js:124:16)
在查阅https://github.com/mikeal/request时看到
Super simple to use
Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.
var request = require('request');request('http://www.google.com', function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body) // Print the google web page. }})
还是会报错,在网上查了好久都没有找到解决方法,暂时记录在此。
0 0
- Error : getaddrinfo ENOTFOUND in node.js
- node pm2 启动 Error: getaddrinfo ENOTFOUND 解决方法
- Got error: getaddrinfo ENOTFOUND
- Got error: getaddrinfo ENOTFOUND;Cannot GET
- webpack getaddrinfo ENOTFOUND localhost 错误
- Error Handling in Node.js
- getaddrinfo ENOTFOUND api.github.com api.github.com:443
- Node.js in ubuntu
- RPC in node.js
- getaddrinfo ENOTFOUND https://api.weixin.qq.com https://api.weixin.qq.com:443
- getaddrinfo EAI_AGAIN error
- Node.js Error: listen EADDRNOTAVAIL
- node.js not linked error
- Node.js Error: listen EADDRINUSE:::
- node.js Error: SSL Error: CERT_UNTRUSTED
- Writing files in Node.js
- Node.js in practice 笔记
- ERROR in Cannot find module 'node-sass'
- shell浅谈之五文本处理工具Vim
- Allegro中删除安装孔
- Java 线程池学习-简介
- 你是想读书,还是想读完书?
- 在Linux Mint 上安装iBus 中文输入法
- Error : getaddrinfo ENOTFOUND in node.js
- 职场分享--职场中如何做一名优秀的员工
- Mongdb、Mysql、Redis、Memcache场景
- C/C++下void*类型指针介绍
- openwrt_meunconfig流程
- 修改TrustedInstaller权限文件(无法删除文件)
- 从M个不同的整数中,选择N个出来排列
- Python函数可变参数定义及其参数传递方式详解
- attribute和property的区别