skip to Main Content

Node js server has been started but not responding when I hit it from web browser

2

Answers


  1. Why would you use apache web server and node.js?

    You can create a very simple web server using node.js

    const http = require('http');
    
    http.createServer((request, response) => {
      const { headers, method, url } = request;
      let body = [];
      request.on('error', (err) => {
        console.error(err);
      }).on('data', (chunk) => {
        body.push(chunk);
      }).on('end', () => {
        body = Buffer.concat(body).toString();
        // At this point, we have the headers, method, url and body, and can now
        // do whatever we need to in order to respond to this request.
      });
    }).listen(8080); // Activates this server, listening on port 8080.
    

    If you’re thinking on using Node.js there are plenty of framework to use, such as Express, Hapi, Resitfy, Fastify etc…

    hope that’s help.

    Login or Signup to reply.
  2. You need “reverse proxy” to achieve this.

    With config like:

    ProxyPass "/"  "http://localhost:8888"
    

    Replace 8888 with the real port your nodejs app listening.

    Check apache’s guide here: https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html.

    Also, check another related question: How to run nodejs application in apache server

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search