Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

5K
Views
localhost didn’t send any data. ERR_EMPTY_RESPONSE nodejs

I'm trying to convert this app to docker but I'm getting this error.

Here's my express.js file

const express = require("express");
const app = express();
const portNumber = 3000;
const sourceDir = "dist";
const expressStaticGzip = require("express-static-gzip");
app.use(
  "/",
  expressStaticGzip(sourceDir, {
    enableBrotli: true,
    orderPreference: ["br", "gz"],
    setHeaders: function(res, path) {
      res.setHeader("Cache-Control", "public, max-age=31536000");
    }
  })
);

app.listen(portNumber, () => {
  console.log(`Express web server started: http://localhost:${portNumber}`);
  console.log(`Serving content from /${sourceDir}/`);
});

here's my dockerfile

FROM node:14
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
CMD [ "node", "express.js" ]

Help is appreciated.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

This is a very common error. When you're broadcasting within a docker container you usually have to listen on host 0.0.0.0 not just localhost. If you listen on localhost docker won't be able to route traffic from outside of the container to the loopback interface within the container.

You can fix this by updating your express code to listen on 0.0.0.0. I believe that's this:

app.listen(portNumber, "0.0.0.0", () => {
  console.log(`Express web server started: http://0.0.0.0:${portNumber}`);
  console.log(`Serving content from /${sourceDir}/`);
});

You'll then need to run the dockerfile with something like:

docker build -t node-app .
docker run -p 3000:3000 node-app
over 4 years ago · Santiago Trujillo Report

0

I was running the angular application using the command ng serve and facing the same problem.

Because the live development server listens to http://localhost:4200 by default.

than I used the command ng serve --host 0.0.0.0 to run the angular project and that solved my problem.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!