NX Workspaces is a powerful tool for scaffolding enterprise level starting points for node.js monorepos with both backend and frontend code in the same repo. This is a starter for developing MERN (MongoDB, Express, React, Node) apps with NX workspaces, jwt and cookies.
Each app in the monorepo lives in it's own folder with the
apps ├── frontend └── backend
The root of the project also includes a libs folder which provides a library with typescript types that can be consumed by both the frontend and backend.
libs ├── types
Run the following command in your terminal.
git clone email@example.com:codsworth9/nx-mern.git
In the .env file update the strings for
NX_JWT_SECRET. You can leave the rest as it is.
Install the dependencies for the monorepo.
Then run the development command
Update all dependencies at once with the command below
If all changes look ok run
Sign up for a free account at Heroku here. Install the Heroku CLI by running the command below in the terminal.
brew tap heroku/brew && brew install heroku
Run the heroku login command
Run the CLI command for creating a new deploy target in your Heroku account.
Post your environments variables to heroku from the terminal.
heroku config:set NX_CONNECTION_STRING=YOUR-MONGO-DB-CONNECTION-STRING NX_JWT_SECRET=YOUR-JWT-SECRET NX_SITE_URL=YOUR-HEROKU-APP-URL
Procfile in the root of your project and add the following
web: yarn start
Make sure all your changes in the repo are commited. Then run
git push heroku master
Use the CLI command below to open up your deployed app in your default browser.
Your NX Mern app is now deployed and running on Heroku.
This repo uses some ideas from the excellent Devistry MERN repo.