Created
December 2, 2020 12:00
-
-
Save webuxmotion/e7d4681718a881965f754eb411a16873 to your computer and use it in GitHub Desktop.
Run React Application on server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const express = require("express"); | |
const app = express(); // create express app | |
// add middlewares | |
app.use(express.static(path.join(__dirname, "..", "build"))); | |
app.use(express.static("public")); | |
app.use((req, res, next) => { | |
res.sendFile(path.join(__dirname, "..", "build", "index.html")); | |
}); | |
// start express server on port 5000 | |
app.listen(5000, () => { | |
console.log("server started on port 5000"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment