I'd like to create a monorepo to manage a fullstack application with a NestJS backend and an Angular frontend that share a package called "shared".
I'd like to do this using NX.
Actually I have checked the NX documentation but I'm a bit confused about the options to chose, there are many (package based monorepos, Angular monorepo, NestJS monorepo), I'm not sure what steps I should follow to use NX properly.
Thanks in advance.
To make long story short - here is a short step by step guide:
npm i -g nx
my-project
. Use this options:
cd my-project
npm i -D @nx/angular @nx/nest @nx/js
nx g @nx/angular:app angular-app
(https://nx.dev/nx-api/angular)nx g @nx/nest:app nest-app
(https://nx.dev/nx-api/nest)nx g @nx/js:lib shared-lib
(https://nx.dev/nx-api/js/generators/library)From this point you have a basic setup. You can import your code form shared library like this:
import { sharedLib } from "@my-project/shared-lib"
Now you can just manually move your code form your external angular and nestjs apps into newly created monorepo projects and move shared code into shared-lib
.
You probably want to use different naming and folder structure so I'd suggest to play a bit with generators and come up with the the solution you'd like.