简体   繁体   English

Node.js localhost:3000 拒绝连接

[英]Node.js localhost:3000 refuses to connect

I am a total beginner of Node.js and I am unable to connect to localhost:3000我是 Node.js 的初学者,我无法连接到 localhost:3000

I use the following code in VS code, hit "node app.js" in terminal, and there is no error comes out in terminal at this point.我在VS代码中使用以下代码,在终端中点击“node app.js”,此时终端中没有错误出现。 However, as I try to access the localhost:3000, it keeps refusing: "ERR_CONNECTION_REFUSED" I searched on the internet for solutions and tried opening ports by creating an inbound rule on security settings, turned IIS on, used 127.0.0.1 instead, and still get refused.但是,当我尝试访问 localhost:3000 时,它一直拒绝:“ERR_CONNECTION_REFUSED”我在互联网上搜索解决方案并尝试通过在安全设置上创建入站规则来打开端口,打开 IIS,改为使用 127.0.0.1,然后仍然被拒绝。 Does anyone have any idea how to solve this?有谁知道如何解决这个问题?

I am using Windows 10我正在使用 Windows 10


const http = require('http');

var server = http.createServer(
    (request, response)=>{
        response.end('hello');
    }
);

server.listen(3000);

Here is how to fix it.这是修复它的方法。 Your probably try to launch your server on a used port.您可能尝试在使用过的端口上启动您的服务器。

 // enter this command in your terminal lsof -i:3000 // this will output the related PID (process ID). Here: 1382. node 1382 name 21u IPv6 blabla 0t0 TCP *:3000 (LISTEN) // kill the PID in use kill -9 1382 //relaunch your server node app.js

I ran it on my computer and that code works fine.我在我的电脑上运行它,该代码运行良好。 I would try other ports to see if they work.我会尝试其他端口,看看它们是否有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在node.js中,控制台显示成功日志,但是localhost:3000未连接 - In node.js, the console displays the success log, but localhost: 3000 is not connected Node.JS:为什么我与 localhost:3000 的连接被拒绝? - Node.JS: Why is my connection to localhost:3000 refused? Node.js服务器在端口3000上运行并在侦听,但Localhost:3000没有发送任何数据 - Node.js server running and listening on Port 3000 but Localhost:3000 didn't send any data GET http://localhost:3000/search 404 (Not Found)REACT.JS, Node.js 和 Axios - GET http://localhost:3000/search 404 (Not Found)REACT.JS, Node.js and Axios Node.js + Apache-https:// localhost:3000 / socket.io / ERR_CONNECTION_REFUSED - Node.js + Apache - https://localhost:3000/socket.io/ ERR_CONNECTION_REFUSED 切换node.js应用程序时localhost:3000不变 - localhost:3000 doesn't change when switching node.js apps Localhost:3000版本与Heroku部署版本的显示方式不同-Node.js - Localhost:3000 Version Displayed Differently from Heroku Deployed Version - Node.js node.js 错误:连接 ECONNREFUSED; 来自本地主机的响应 - node.js Error: connect ECONNREFUSED; response from localhost 使用node.js进行MongoDB设置:错误:无法连接到[localhost:27017] - MongoDB setup with node.js: Error: failed to connect to [localhost:27017] 无法连接到本地主机端口 8000:Node.js 中的连接被拒绝 - Failed to connect to localhost port 8000: Connection refused in Node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM