title: Failed to connect to localhost port 8000: Connection refused in Node.js
body: <p>I'm trying to connect to the HTTP server in node.js.
  I've spent my whole day searching online to solve my issue but unfortunately, it is of no use.</p>
  
  <p>This is a simple code I wrote taking reference from official Node.js <a href="https://nodejs.org/en/knowledge/HTTP/servers/how-to-create-a-HTTP-server/" rel="nofollow noreferrer">documentation</a>.</p>
  
  <p><strong>Index.js</strong></p>
  
  <pre><code>const http = require('http');
  
  const requestListener = function (req, res) {
    res.writeHead(200);
    res.end('Hello, World!');
  }
  
  const server = http.createServer(requestListener);
  server.listen(8080);
  </code></pre>
  
  <p><strong>The code I am running inside CMD terminal</strong></p>
  
  <pre><code>curl localhost:8080
  </code></pre>
  
  <p>This returns the following error:
  <a href="https://i.stack.imgur.com/Wic77.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wic77.png" alt="enter image description here"></a></p>
  
  <p>I know this questions have been asked a thousands time in stack overflow but none fixed my issue. Anyone can help me?</p>