{"id":15764437,"url":"https://github.com/timsusa/heroku-example-node-react","last_synced_at":"2025-03-31T10:20:47.444Z","repository":{"id":85350744,"uuid":"128597832","full_name":"TimSusa/heroku-example-node-react","owner":"TimSusa","description":null,"archived":false,"fork":false,"pushed_at":"2019-01-27T01:46:07.000Z","size":173,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-19T06:44:17.666Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TimSusa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-08T04:32:51.000Z","updated_at":"2018-04-08T04:34:40.000Z","dependencies_parsed_at":"2023-03-03T13:45:44.943Z","dependency_job_id":null,"html_url":"https://github.com/TimSusa/heroku-example-node-react","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"ebf9230dbbcbaf20be28596c89bb787a76c5fe3c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimSusa%2Fheroku-example-node-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimSusa%2Fheroku-example-node-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimSusa%2Fheroku-example-node-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimSusa%2Fheroku-example-node-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimSusa","download_url":"https://codeload.github.com/TimSusa/heroku-example-node-react/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246450478,"owners_count":20779421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-04T12:03:31.552Z","updated_at":"2025-03-31T10:20:47.417Z","avatar_url":"https://github.com/TimSusa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# create-react-app with a Node server on Heroku\n\nA minimal example of using a Node backend (server for API, proxy, \u0026 routing) with a [React frontend](https://github.com/facebookincubator/create-react-app).\n\nTo deploy a frontend-only React app, use the static-site optimized  \n▶️ [create-react-app-buildpack](https://github.com/mars/create-react-app-buildpack)\n\n⤵️ [Switching from create-react-app-buildpack](#switching-from-create-react-app-buildpack)?\n\n\n## Design Points\n\nA 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:\n\n  1. [`package.json`](package.json) for [Node server](server/) \u0026 [Heroku deploy](https://devcenter.heroku.com/categories/deployment)\n      * `heroku-postbuild` script compiles the webpack bundle during deploy\n      * `cacheDirectories` includes `react-ui/node_modules/` to optimize build time\n  2. [`react-ui/package.json`](react-ui/package.json) for [React web UI](react-ui/)\n      * generated by [create-react-app](https://github.com/facebookincubator/create-react-app)\n\nIncludes a minimal [Node Cluster](https://nodejs.org/docs/latest-v8.x/api/cluster.html) [implementation](server/index.js) to parallelize the single-threaded Node process across the available CPU cores.\n\n## Demo\n\n[Demo deployment](https://cra-node.herokuapp.com/): example API call from the React UI is [fetched with a relative URL](react-ui/src/App.js#L16) that is served by an Express handler in the Node server.\n\n\n## Deploy to Heroku\n\n```bash\ngit clone https://github.com/mars/heroku-cra-node.git\ncd heroku-cra-node/\nheroku create\ngit push heroku master\n```\n\nThis deployment will automatically:\n\n  * detect [Node buildpack](https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-nodejs)\n  * build the app with\n    * `npm install` for the Node server\n    * `heroku-postbuild` for create-react-app\n  * launch the web process with `npm start`\n    * serves `../react-ui/build/` as static files\n    * customize by adding API, proxy, or route handlers/redirectors\n\n⚠️ Using npm 5’s new `package-lock.json`? We resolved a compatibility issue. See [PR](https://github.com/mars/heroku-cra-node/pull/10) for more details.\n\n👓 More about [deploying to Heroku](https://devcenter.heroku.com/categories/deployment).\n\n\n## Switching from create-react-app-buildpack\n\nIf an app was previously deployed with [create-react-app-buildpack](https://github.com/mars/create-react-app-buildpack), then a few steps are required to migrate the app to this architecture:\n\n1. Remove **create-react-app-buildpack** from the app; [heroku/nodejs buildpack](https://devcenter.heroku.com/articles/nodejs-support#activation) will be automatically activated\n  \n    ```bash\n    heroku buildpacks:clear\n    ```\n1. Move the root React app files (including dotfiles) into a `react-ui/` subdirectory\n\n    ```bash\n    mkdir react-ui\n    git mv -k [!react-ui]* react-ui/\n    mv node_modules react-ui/\n    \n    # If you see \"fatal: Not a git repository\", then fix that error\n    mv react-ui/.git ./\n    ```\n    ⚠️ *Some folks have reported problems with these commands. Sorry if they do not work for you, know that the point is to move **everything** in the repo into the `react-ui/` subdirectory. Except for `.git/` which should remain at the root level.* \n1. Create a root [`package.json`](package.json), [`server/`](server/), \u0026 [`.gitignore`](.gitignore) modeled after the code in this repo\n1. Commit and deploy ♻️\n  \n    ```bash\n    git add -A\n    git commit -m 'Migrate from create-react-app-buildpack to Node server'\n    git push heroku master\n    ```\n  \n\n## Local Development\n\n### Run the API Server\n\nIn a terminal:\n\n```bash\n# Initial setup\nnpm install\n\n# Start the server\nnpm start\n```\n\n\n### Run the React UI\n\nThe React app is configured to proxy backend requests to the local Node server. (See [`\"proxy\"` config](react-ui/package.json))\n\nIn a separate terminal from the API server, start the UI:\n\n```bash\n# Always change directory, first\ncd react-ui/\n\n# Initial setup\nnpm install\n\n# Start the server\nnpm start\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimsusa%2Fheroku-example-node-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimsusa%2Fheroku-example-node-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimsusa%2Fheroku-example-node-react/lists"}