Skip to content

Instantly share code, notes, and snippets.

@webuxmotion
Created December 2, 2020 12:00
Show Gist options
  • Save webuxmotion/e7d4681718a881965f754eb411a16873 to your computer and use it in GitHub Desktop.
Save webuxmotion/e7d4681718a881965f754eb411a16873 to your computer and use it in GitHub Desktop.
Run React Application on server
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