J4N
J4N

Reputation: 20761

How to create module/controller of NestJs in a mono-repo with Nx?

I'm trying to use the Nx monorepo approach. I've created a project with Angular & NestJs:

npx create-nx-workspace --preset=angular-nest

But now I'm trying to create modules. On a standalone NestJs project, I would usually do something like:

nest g module auth

But if I do it in the root the file doesn't get created in the correct folder. What is the expected approach to develop in such multi-repo environment? should I open each app subfolder in a dedicated VS code? But then I guess I would loose the benefit of shared libraries?

I also think I could move my VS Code terminal in the correct folder, but then each time I open a new one I should go into the correct folder, pretty sure it will leads me to some errors.

THanks

Upvotes: 1

Views: 3819

Answers (1)

Jay McDoniel
Jay McDoniel

Reputation: 70490

If you're in an Nx workspace, you should be using the nx generator instead of the nest generator.

nx g @nrwl/nest:module auth
nx g @nrwl/nest:controller auth

I believe the generator will ask for which project as well. There's also the Nx Console Plugin for VSCode where you can see the changes before committing to any of them.

Upvotes: 3

Related Questions