Can I use this technique to create a a shared module package.
I have a Lerna monorepo project with two implementations one rest and one graphql, and I really want to create a common shared package, for example to Share the auth module in both rest and graphql packages. Can I extract the auth and users modules (same as nestjs docs) into a package(local ir registery), and reuse it in this two packages, and maybe other new projects?
Or is a better way to share common packages in nestjs to not Dry and duplicate same code?
Hi, I think you just posted this question on the discord channel? Here's what I wrote there:
I assume you want to keep the packages private, so I think you have a couple of options. One is to use a private npm registry -- either with a paid account at npmjs.com, or hosting one locally (I have experimented with Verdaccio, and it seems excellent, though I've only just played around with it). Another is to consider a monorepo. I candidly don't have any experience with a monorepo, but a lot of folks on here do actively use one, so I'm sure one or more will chime in if you want to go that route. Good luck!
Hopefully some of the other community members will chime in with thoughts.
I already use monorepo and Verdaccio.
But the question os not related with publish. I try to ask about extract auth and users modules to a new package to share in my 2 projects. Ex I want to create for ex a package like @acme/nestjs-auth and re,-use it, that why I ask it. Sorry if I cant explain better, you already note that I have some issues with English eheheh
So I may not be understanding, but it seems like you're asking about re-using a package in another project. To me, that sounds exactly like what I was addressing. So, you would npm publish @acme/nestjs-auth (if you want it public, that's exactly the recipe outlined in this article; if you want it private, I addressed that above), then, in project A, you'd npm install @acme/nestjs-auth and inside your project a, import { blah } from @acme/nestjs-auth. You could do the same inside project b.
If you just mean sharing a module within a project, that is a separate topic, and is about the Nest module system.
I hope that clarifies somewhat. Ask further if I'm missing the point!
Another great post @john
Thanks
Can I use this technique to create a a shared module package.
I have a Lerna monorepo project with two implementations one rest and one graphql, and I really want to create a common shared package, for example to Share the auth module in both rest and graphql packages. Can I extract the auth and users modules (same as nestjs docs) into a package(local ir registery), and reuse it in this two packages, and maybe other new projects?
Or is a better way to share common packages in nestjs to not Dry and duplicate same code?
Thanks
Hi, I think you just posted this question on the discord channel? Here's what I wrote there:
Hopefully some of the other community members will chime in with thoughts.
Thanks @john
I already use monorepo and Verdaccio.
But the question os not related with publish. I try to ask about extract auth and users modules to a new package to share in my 2 projects. Ex I want to create for ex a package like @acme/nestjs-auth and re,-use it, that why I ask it. Sorry if I cant explain better, you already note that I have some issues with English eheheh
Thanks
No worries @Mário.
So I may not be understanding, but it seems like you're asking about re-using a package in another project. To me, that sounds exactly like what I was addressing. So, you would
npm publish @acme/nestjs-auth
(if you want it public, that's exactly the recipe outlined in this article; if you want it private, I addressed that above), then, in project A, you'dnpm install @acme/nestjs-auth
and inside your project a,import { blah } from @acme/nestjs-auth
. You could do the same inside project b.If you just mean sharing a module within a project, that is a separate topic, and is about the Nest module system.
I hope that clarifies somewhat. Ask further if I'm missing the point!
Thanks John,
Yes Im asking about sharing a module within a project
@rubin sent me a GitHub link in discord that seems will Help me with issue. Thanks John for your paciente and kind answear :)
Looking forward for next great nestjs posts.
Hi Mário, how are you doing?
I need to do exactly what you asked for, how did you dealed with the problem?
Thank you.
Hello Samuel
I don't remember, I must check my project, but the of out friend @rubin put me in the right track.
When I get to home I Will check it....
O see that @rubin repo link os not on this thread, I paste it later
Hello Samuel
here are my notes
includes the link to repo that I follow to get it working from our friend @rubiin
I hope this helps :)
NOTES
Links
a example to create a nestjs package with dynamic modules :)
Tooling
Publish
Us in NestJs from file system, ideal for developing
Use in NestJs lerna project from NPM registry
Install in App
app.module.ts
ex from graphql project