Home > front end >  Node.js / curl(7) failed to connect to localhost port 3000. How to fix it?
Node.js / curl(7) failed to connect to localhost port 3000. How to fix it?

Time:01-05

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"

This also happens with other ports oder when i type 127.0.0.1 directly. I also disabled my firewall with ufw and allow 3000 with ufw. I am working with VirtualBox for a uni project. I am running everything in the VM. The goal is to cluster with docker and i need the web server for loadbalancing in the end. Thanks!

CodePudding user response:

Are you sure your server is running? After "node hello.js" everything is fine? Is the cursor just blinking? Please, show your code here (hello.js)

CodePudding user response:

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.

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.

  • Related