Skip to content

Instantly share code, notes, and snippets.

@achimoraites
Created November 13, 2018 15:09
Show Gist options
  • Save achimoraites/20b3e7e1c4d796bb358d67738d9e53fb to your computer and use it in GitHub Desktop.
Save achimoraites/20b3e7e1c4d796bb358d67738d9e53fb to your computer and use it in GitHub Desktop.
Simple Express Server to serve a react app located in client dir
const express = require('express');
const app = express();
// serve up production assets
app.use(express.static('client/build'));
// serve up the index.html if express does'nt recognize the route
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
// if not in production use the port 5000
const PORT = process.env.PORT || 5000;
console.log('server started on port:',PORT);
app.listen(PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment