Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

responding with index.html in express and react

I have an express app where inside it has a create-react-app. when the user goes to root url I want to show the index.html present in create-react-app public folder. Here is my code for index.js in express app

const express = require("express");
const app = express();

app.get('/',function(req,res){


});

const PORT = process.env.PORT || 5000;
app.listen(PORT);

Here is my project directory

like image 398
kamalakshi hegde Avatar asked Oct 26 '25 09:10

kamalakshi hegde


1 Answers

You need this line: app.use(express.static('public')). See here: https://expressjs.com/en/starter/static-files.html

like image 195
mikkelrd Avatar answered Oct 28 '25 22:10

mikkelrd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!