2

Is there a recommended pattern to share a schema (or a module in general) between a React client and an Express backend? I'd like to do the same validation on the client as the server and would rather not repeat myself.

Naively, I've bodged it for development through requiring the schema module from the client in the server code:

const schema = require ('./../../../client/src/schema.js');

However, for production the schema gets packed up with everything else so isn't deployed in its own right.

Mat
  • 82,161
  • 34
  • 89
  • 109
  • 1
    you could use yarn workspaces as suggested [here](https://stackoverflow.com/a/59596672/9238134). other way, structure your src folder with client, server and shared folders like this [boilerplate](https://github.com/gilamran/fullstack-typescript) – buzatto May 24 '20 at 01:41

0 Answers0