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

375
Views
How to display static files from backend into React?

I have a React application with an Express-Node.js backend. I have a proxy that links both. Now, I have some static files in a directory within the backend. When I make the request and place the response in the "src" attribute of an image tag, I can display the image, but same result does not happen when I try the link in the browser.

This works in the browser: http://localhost:5000/public/image.png /EXAMPLE ROUTE/

This doesn't: https://localhost/image.png /EXAMPLE ROUTE/

My backend code:

const express = require('express');
const app = express();
const PORT = process.env.PORT;

app.use('/images', express.static(__dirname + '/public'));

app.listen(PORT, (err) => {
  if(err) {
    throw err;
  } else {
    console.log(`Running on http://localhost:${PORT}/`);
  }
});

My react code:

import React from 'react';
import './App.css?v=1';

function App() {
    return (
        <div className="App">
            <img src="/images/image.png" alt="Logo" /> /*THIS TOTALLY WORKS*/
            <img src="https://localhost/images/image.png" alt="Logo" /> /*THIS TOTALLY WORKS*/
        </div>
    );
}

export default App;

My problem comes when I go to the browser and type the URL: https://localhost/images/image.png -> This will not display the image the way http://localhost:5000/public/image.png will and all I get is a blank page.

In React's package.json file, I proxy to the backend.

If clarification is needed, let me know. Thanks, in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

do like me

const express = require('express');
const app = express();
const path = require('path');


 this.app.use("/public", express.static(path.join(__dirname, "public")));


about 4 years ago · Juan Pablo Isaza 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!