Javascript 如何解决;Firefox可以';t在127.0.0.1:8081建立与服务器的连接”;
运行node js程序时在浏览器上捕获到错误这里是您使用错误名称的问题Javascript 如何解决;Firefox可以';t在127.0.0.1:8081建立与服务器的连接”;,javascript,node.js,client-server,Javascript,Node.js,Client Server,运行node js程序时在浏览器上捕获到错误这里是您使用错误名称的问题response应该是response。 var http = require("http"); http.createServer(function (request, response){ response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('hello suneha\n'); }).listen(8081); console.
response
应该是response。
var http = require("http");
http.createServer(function (request, response){
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('hello suneha\n');
}).listen(8081);
console.log('server running at http://127.0.0.1:8081/');
可能是其他进程使用了8081端口。
我尝试过使用不同的端口号,它工作正常首先,您使用的是8080而不是8081端口。那么,当你运行节点程序时,有没有错误?或者只是运行在…消息上的
服务器?尝试访问页面时,节点中是否有错误?你在windows上运行这个吗?windows是否弹出关于允许节点充当服务器的对话框?你允许吗?发帖时输入错误,抱歉。我已经编辑了这个问题。8081端口仅在listenIt下工作正常。我已尝试在本地机器的http.createServer(函数(请求、响应)上将response
替换为response
{
而且运行良好。我是node js的初学者
-这与什么有关呢?抱歉,发帖时输入错误。@SunehaBanuJ我在本地复制了相同的内容。只要运行node test.js
就可以了,假设test.js拥有上述所有代码。它在所有浏览器上都运行良好。
http.createServer(function (request, response){