Skip to content

Instantly share code, notes, and snippets.

@rajputankit22
Created August 9, 2020 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajputankit22/31bfefd8182b362359404a6a56b7f5da to your computer and use it in GitHub Desktop.
Save rajputankit22/31bfefd8182b362359404a6a56b7f5da to your computer and use it in GitHub Desktop.
server.js file code for deploy a react app to node server.
const express = require("express");
const path = require("path");
const app = express();
app.use(express.static(path.join(__dirname, "build")));
app.post("/", function (req, res) {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
app.get("/*", function (req, res) {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
app.listen(process.env.PORT || 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment