This simple example app demonstrates a number of techniques that I've been researching in order to improve developers experience:
Yarn workspaces are used to:
- break down the monorepo into smaller, easy to compose modules
- simplify build steps and hosting
In particular, the env workspace
- handles all env vars for both API and UI
- centralize and greatly simplify env vars management
- automatically validates all env vars, using the amazing envalid
To validate all env vars, for example during prebuild, and ensure the build is cancelled if any is missing:
node -r esm env
Using the esm loader
- Enables ES6 features in node, like
import
statements instead ofrequires
\o/ \o/ \o/ - Provides a more smooth & consistent coding experience
- Makes it possible to have a unified env vars management, shared seamlessly by both UI and API.
For example, these commands allow validate the env vars, then pass them to the scripts:node -r esm -r env api/server.js
node -r esm -r env ui/build.js
- Projects in early stages
- Company internal tools: intranets, ...
- Basically, small projects where having a more unified frontend + backend served together (on 1 dyno in the Heroku case) is all you need.
Runing locally (in development):
yarn dev
starts both UI and API server in parallel, in dev mode
Hosting on Heroku:
Shoud work out of the box, just normally deploy to Heroku.
After build, the backend will both serve the UI and API (under /graphql
)