Workspaces

The main concept of Multijet is the same as every other Node.js based monorepo: workspaces.

To know more about workspaces, you can read the official npm workspaces documentation.

In Multijet, there are two workspaces by default:

  • microservices

  • libs

Workspaces are defined in the project's root package.json file.

Microservices

Inside this workspace by default there are multiple Node.js projects using the Fastify web framework. If you just created a new project, you will find an example microservice running a simple hello-world REST API.

By default, microservices can install and use shared packages in the libs workspace.

Libs

As the microservices workspace, this one also can contain multiple Node.js projects. These packages can be installed and used either by a microservice or by another lib.

Example

Let's say you have a project with the following structure:

my-project/
├── libs/
│   ├── lib-A
│   └── lib-B
└── microservices/
    └── microservice-1

For this example, we want to use lib-A in microservice-1, and lib-B in lib-A

First, let's install lib-B as a dependency of lib-A. In the root of your project run this command:

npm install @libs/lib-B -w libs/lib-A

This command is a standard npm install but, instaed of installing a package from the npm registry, we actually add a local package (lib-B) contained in the libs workspace.

If we didn't include -w libs/lib-A npm would have installed the package globally in the project. By using the -w option we tell npm to install that package for the specific project in the workspace (in this case the workspace is libs and the project is lib-A)

Now that we have installed lib-B in lib-A, you can probably guess how we can do this with microservice-1 and lib-A:

npm install @libs/lib-A -w microservices/microservice-1

Note that the -w option is not required if you are already in the directory of the project that needs the dependency:

cd microservices/microservice-1
npm install @libs/lib-A

This will do the same exact thing as the previous command.

Last updated