简体   繁体   English

Node.js / curl(7) 无法连接到本地主机端口 3000。如何解决?

[英]Node.js / curl(7) failed to connect to localhost port 3000. How to fix it?

response from testing code hello.js i am trying to create a web service with node.js. Unfortunately after implementing the application hello.js i am only able to test successfully "node hello.js", but furthermore when i type in "curl http://localhost:3000" i am getting "curl: (7) Failed to connect to localhost port 3000: connection estavlishment rejected"测试代码 hello.js的响应我正在尝试使用 node.js 创建一个 web 服务。不幸的是,在实施应用程序 hello.js 之后,我只能成功测试“node hello.js”,但是当我输入“curl http”时: //localhost:3000”我收到“curl: (7) 无法连接到本地主机端口 3000:连接建立被拒绝”

This also happens with other ports oder when i type 127.0.0.1 directly.当我直接键入 127.0.0.1 时,其他端口也会发生这种情况。 I also disabled my firewall with ufw and allow 3000 with ufw.我还使用 ufw 禁用了我的防火墙,并允许 3000 使用 ufw。 I am working with VirtualBox for a uni project.我正在与 VirtualBox 合作进行一个 uni 项目。 I am running everything in the VM.我在 VM 中运行所有内容。 The goal is to cluster with docker and i need the web server for loadbalancing in the end.目标是与 docker 集群,最后我需要 web 服务器进行负载平衡。 Thanks!谢谢!

Are you sure your server is running?你确定你的服务器正在运行吗? After "node hello.js" everything is fine?在“node hello.js”之后一切都很好吗? Is the cursor just blinking? cursor 只是在闪烁吗? Please, show your code here (hello.js)请在此处显示您的代码 (hello.js)

The issue here that you use same terminal for multiple processes.这里的问题是您对多个进程使用同一个终端。 As soon as you start the server, it holds the terminal.一旦启动服务器,它就会拥有终端。 It means when you press Ctrl + C (^c in terminal output), you stop the server.这意味着当您按 Ctrl + C(终端输出中的 ^c)时,您将停止服务器。

In your case you should use two terminals.在您的情况下,您应该使用两个终端。 In the first one you start the server (and do nothing with this particular terminal), in second one you make the request.在第一个中你启动服务器(并且不对这个特定的终端做任何事情),在第二个中你发出请求。 Or you can change second step and make request from browser (it will be GET request by default), Postman, Insomnia etc.或者您可以更改第二步并从浏览器发出请求(默认为 GET 请求)、Postman、Insomnia 等。

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

相关问题 Node.js localhost:3000 拒绝连接 - Node.js localhost:3000 refuses to connect 终端卷曲:(7)无法连接到localhost端口3000:连接被拒绝 - Terminal curl: (7) Failed to connect to localhost port 3000: Connection refused 无法连接到本地主机端口 8000:Node.js 中的连接被拒绝 - Failed to connect to localhost port 8000: Connection refused in Node.js 使用 Node.js 和 mySQL 在 localhost:3000 上登录失败 - Login Failed on localhost:3000 using Node.js and mySQL Node.js服务器在端口3000上运行并在侦听,但Localhost:3000没有发送任何数据 - Node.js server running and listening on Port 3000 but Localhost:3000 didn't send any data (7) 连接localhost 3000端口失败:连接被拒绝 - (7) Failed to connect to localhost port 3000: Connection refused 使用Node.js连接到localhost:3000服务器 - Connecting to a localhost:3000 server with Node.js 如何在端口80上将node.js本地主机与端口90上的apache mysql连接起来? - How to connect node.js localhost at port 80 with apache mysql at port 90? 如何在node.js应用程序中使用publicIP:3000代替localhost:3000 - How to use publicIP:3000 in place of localhost:3000 in node.js application 无法在 node.js 应用程序中运行 localhost:3000,错误:无法在视图目录“./views”中查找视图“home” - Unable to run localhost:3000 in node.js app, Error: Failed to lookup view "home" in views directory "./views"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM