Creating a mono repo for multiple applications

If you are planning to develop multiple applications working together, using the same technology, it is advantageous to place all of them in the same Git repository. This way you can use relative paths to refer to shared functions to access the same database, React components, and images to make the pages look consistent. As all are in the same repository, the CI/CD pipeline will also find those during application building and testing.

If you use Node.js packages, use PNPM for package management to rationalize the node modules and store them in the top level node_modules directory and use symbolic links to point to those from other locations. See Install pnpm.

To set up the mono repo for multiple Node.js applications

Create the directory structure

Create the root directory of the repository and the apps and packages subdirectories.

mkdir -p MY_APP_SUITE
cd MY_APP_SUITE
mkdir -p apps
mkdir -p packages

Add configuration files to the root directory

package.json

Set the versions of node and pnpm in the file below and save it in the root of the repository

{
  "name": "MY_APP_SUITE_NAME",
  "version": "1.0.0",
  "private": true,
  "description": "MY DESCRIPTION",
  "main": "index.js",
  "scripts": {
  },
  "keywords": [],
  "author": "MY NAME",
  "dependencies": {
  },
  "devDependencies": {
  },
  "config": {
  },
  "engines": {
    "node": ">=24.11.0",
    "pnpm": ">=10.15.1"
  },
  "packageManager": "pnpm@10.15.1"
}

pnpm-workspace.yaml

This file tells PNPM where the applications and shared packages will be to be able to reuse node-packages.

packages:
  - "apps/*"
  - "packages/*"

Add the applications

If you already have existing applications, copy their directory structures into the apps directory and delete the node_modules directories. PNPM will recreate those and create symbolic links to point to the top level node_modules directory.

To create a new React Router web application, open a terminal in the apps directory and follow the instructions at Creating a new React Router application.

As we use PNPM to rationalize the node modules for all applications, do not install the node modules in the individual application directories. Once the application structure been created open a terminal in the root of the mono repo and execute

pnpm install

Based on the packages list in the pnpm-workspace.yaml file, PNPM will install all necessary node modules for all applications and packages in the entire workspace, which is the current mono repo.

Leave a comment

Your email address will not be published. Required fields are marked *