Serving react statically with express

This page summarizes the projects mentioned and recommended in the original post on /r/node

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • react-specials

    Repo for my React specials app.

  • Here's what I found testing out my app locally (Git repo here). First note that my Express app is installed in the root folder of the project, and it is its own Node project (e.g. has its own package.json file, etc). My React app is installed in a sub-folder (client), and it is its own separate Node project.

  • webpack-dev-middleware

    A development middleware for webpack

  • Are you using webpack? If so, they have a middleware for exactly this case: https://github.com/webpack/webpack-dev-middleware. The example there should be added to your express script with some form of conditional statement to use express.static in your deployment and webpack-dev-middleware in dev.

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • concurrently

    Run commands concurrently. Like `npm run watch-js & npm run watch-less` but better.

  • Lastly if you want to run your dev build tool and backend as a single command you could try something like pm2 (https://www.npmjs.com/package/pm2) or concurrently (https://www.npmjs.com/package/concurrently). This isn't necessary but might be a nice-to-have. NPM workspaces could help you organize this with a common package.json file too. (https://docs.npmjs.com/cli/v7/using-npm/workspaces)

  • PM2

    Node.js Production Process Manager with a built-in Load Balancer.

  • Lastly if you want to run your dev build tool and backend as a single command you could try something like pm2 (https://www.npmjs.com/package/pm2) or concurrently (https://www.npmjs.com/package/concurrently). This isn't necessary but might be a nice-to-have. NPM workspaces could help you organize this with a common package.json file too. (https://docs.npmjs.com/cli/v7/using-npm/workspaces)

  • restfuncs

  • See this example and use the dev_faster... run script. It uses a dev/production switch to see if it should run the devserver or host the pre-build static files as you see when you look at server.ts

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts