节点服务器正在运行但localhost拒绝连接 [英] node server running but localhost refusing to connect

查看:146
本文介绍了节点服务器正在运行但localhost拒绝连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试让最简单的节点服务器与浏览器交互,其中包括:

Trying to get the simplest node server interacting with the browser, with this:

var http = require('http');


http.createServer(function(req, res){

  res.writeHead( 200, { "content-Type" : 'text/plain' } )
  res.send('Hello world');

}).listen(1337, '192.168.1.2');

但是localhost不会这样做..

but localhost won't do it..

localhost refused to connect

这是IPv4地址。我在这里错过了什么吗?

Thats the IPv4 address. Am I missing something here?

推荐答案

使用0.0.0.0,它将同时适用于'192.168.1.2'和localhost。

Use 0.0.0.0 and it will work both '192.168.1.2' and localhost.

这篇关于节点服务器正在运行但localhost拒绝连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆