Deployment


Introduction

npm run build creates a build directory with a production build of your app. Set up your favorite HTTP server so that a visitor to your site is served index.html, and requests to static paths like /static/js/main.<hash>.js are served with the contents of the /static/js/main.<hash>.js file.

Static Server

For environments using Node, the easiest way to handle this would be to install serve and let it handle the rest:
npm install -g serve
serve -s build
The last command shown above will serve your static site on the port 5000. Like many of serve’s internal settings, the port can be adjusted using the -l or --listen flags:
serve -s build -l 4000
Run this command to get a full list of the options available:
serve -h

Other Solutions

You don’t necessarily need a static server in order to run a Create React App project in production. It also works well when integrated into an existing server side app.

Express

Express is a fast, unopinionated, minimalist web framework for Node.js. Here’s a programmatic example:
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'build')));
app.get('/', function(req, res) {
  res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(9000);

Netlify

Deploy modern static websites with Netlify. Get CDN, Continuous deployment, 1-click HTTPS, and all the services you need.
To do a manual deploy to Netlify’s CDN:
npm install netlify-cli -g
netlify deploy
Choose build as the path to deploy.
To setup continuous delivery:
With this setup Netlify will build and deploy when you push to git or open a pull request:
  1. Start a new netlify project
  2. Pick your Git hosting service and select your repository
  3. Click Build your site