js无法在Windows上解析

js无法在Windows上解析

本文介绍了Node.js无法在Windows上解析'localhost'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在Windows下的node.js中产生异常:

The following code produces an exception in node.js under windows:

var Socket = require("net").Socket;

socket = new Socket();
socket.connect(80, "localhost");

这是消息:

    events.js:2083: Uncaught Error: getHostByName ENOTFOUND

当我删除localhost时,它可以正常工作.是什么原因造成的?我尝试关闭防火墙,但没有效果.

When I remove localhost, it works fine. What could be causing this?I tried turning the firewall off, but to no effect.

推荐答案

node.js使用c-ares解析器,而完全忽略系统解析器.因此,有关C:\ WINDOWS \ system32 \ drivers \ etc \ hosts的建议可能无关紧要.

node.js uses c-ares resolver and ignores system resolver completely. So the advices regarding C:\WINDOWS\system32\drivers\etc\hosts are probably irrelevant.

c-ares库读取某些系统配置文件-例如在Windows和Cygwin上,其读取为/etc/resolv.conf.因此,您应该检查它是否读取/etc/hosts或C:\ WINDOWS \ system32 \ drivers \ etc \ hosts.如果没有并且没有对本地主机的内置支持-那么您将不得不使用127.0.0.1

c-ares library reads certain system config files - e.g. on Windows and Cygwin it reads /etc/resolv.conf. So you should check if it reads /etc/hosts or C:\WINDOWS\system32\drivers\etc\hosts. If it doesn't and doesn't have builtin support for localhost - then you will have to use 127.0.0.1

这篇关于Node.js无法在Windows上解析'localhost'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 05:12