[英]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.