romran / react-books-store-500

Home Page:https://books-store-fe.herokuapp.com/https://github.com/romran/react-books-store

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

create-react-app with a Node server on Heroku

A minimal example of using a Node backend (server for API, proxy, & routing) with a React frontend.

Design Points

A combo of two npm projects, the backend server and the frontend UI. So there are two package.json configs and thereforce two places to run npm commands:

  1. package.json for Node server & Heroku deploy
    • heroku-postbuild script compiles the webpack bundle during deploy
    • cacheDirectories includes react-ui/node_modules/ to optimize build time
  2. react-ui/package.json for React web UI

Includes a minimal Node Cluster implementation to parallelize the single-threaded Node process across the available CPU cores.

Deploy to Heroku

git clone https://github.com/mars/heroku-cra-node.git
cd heroku-cra-node/
heroku create
git push heroku master

This deployment will automatically:

  • detect Node buildpack
  • build the app with
    • npm install for the Node server
    • heroku-postbuild for create-react-app
  • launch the web process with npm start
    • serves ../react-ui/build/ as static files
    • customize by adding API, proxy, or route handlers/redirectors

⚠️ Using npm 5’s new package-lock.json? We resolved a compatibility issue. See PR for more details.

👓 More about deploying to Heroku.

Local Development

Run the API Server

In a terminal:

# Initial setup
npm install

# Start the server
npm start

Run the React UI

The React app is configured to proxy backend requests to the local Node server. (See "proxy" config)

In a separate terminal from the API server, start the UI:

# Always change directory, first
cd react-ui/

# Initial setup
npm install

# Start the server
npm start

About

https://books-store-fe.herokuapp.com/https://github.com/romran/react-books-store

License:MIT License


Languages

Language:CSS 46.5%Language:JavaScript 35.0%Language:HTML 18.5%