DEV Community

Discussion on: Publishing NestJS Packages with npm

johnbiundo profile image
John Biundo Author

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'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!

Thread Thread
koakh profile image
Mário Monteiro • Edited

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.

Thread Thread
samxdesc profile image

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.

Thread Thread
koakh profile image
Mário Monteiro

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

Thread Thread
solidarynetwork profile image

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 :)



a example to create a nestjs package with dynamic modules :)


CLI command to install npm peerDependencies. This can be useful when developing modules.

$ sudo npm install -g npm-install-peers
$ npm-install-peers


# build
$ npm run build
# publish
$ npm publish
# unPublish
# npm unpublish <package-name>@<version>
$ npm unpublish @koakh/nestjs-auth-quick-config@1.2.2

Us in NestJs from file system, ideal for developing

# create symbolic link
$ cd NodeNestJsHyperLedgerConvectorRestStarter/node_modules/@koakh
$ ln -s ../../../../../Node/@NestPackages/@koakh/nestjs-auth-quick-config/

After changes don't forget to npm run build

Use in NestJs lerna project from NPM registry

# install dependency
$ npx lerna add @koakh/nestjs-auth-quick-config --scope @convector-sample/server-graphql
$ npx lerna clean
$ npx lerna bootstrap

Install in App


ex from graphql project

import { AuthQuickConfigModule } from '@koakh/nestjs-auth-quick-config';

  imports: [
      installSubscriptionHandlers: true,
      autoSchemaFile: 'schema.gql',
      jwtSecret: 'secretKey',
      jwtExpiresIn: '1h',
      getByUsername: (username: string) => 'admin',