Skip to content

Instantly share code, notes, and snippets.

@reciosonny
Created April 8, 2018 06:46
Show Gist options
  • Select an option

  • Save reciosonny/7d52e01dc36dbe22bc98c06b38050a25 to your computer and use it in GitHub Desktop.

Select an option

Save reciosonny/7d52e01dc36dbe22bc98c06b38050a25 to your computer and use it in GitHub Desktop.
Code snippet for setting up react app inside node #nodejs #javascript
if (process.env.NODE_ENV === 'production') {
//Express will serve up production assets
//like our main.js file, or main.css file
app.use(express.static('client/build'));
//Express will serve up the index.html file
//if it doesn't recognize the route
//note 1: if it doesn't recognize the file being scanned above(static/client/build), then it will go through here to find the index.html file. This route is a catch-all scenario just to load the client app in express server.
const path = require('path');
app.get('*', (req, res) => {
res.sendfile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment