In case if you don’t know about nest please check https://docs.nestjs.com

NestJS, it is a TypeScript Node.js framework that helps you build enterprise-grade efficient and scalable Node.js applications.

As NestJS is growing faster in demand its development time of nestjs app should a be also growing faster.

Let’s imagine a real-world scenario, where we need to expose CRUD endpoints for 2 entities, let’s say Userand Product entities. Following the best practices, for each entity we would have to perform several operations, as follows:

  • Generate a module (nest g mo) to keep code organized and establish clear boundaries (grouping related components)

That takes a hour to do it.

To help speed up this repetitive process, NestJS CLI now provides a new generator (schematic) that automatically generates all the boilerplate code to help us avoid doing all of this, and make the developer experience much simpler.

REQUIREMENTS

install the latest version of @nestjs/cli and @nestjs/schematics packages.

once done with the installation just run this command

nest g resource modulename

This command with generate some question like this gif

Select your preference and it will create all the needs files.

What you saved an hour .Isn’t it amazing.I loved It….

one life saving hint :->Don’t say this feature to your managers haa haa…

Likewise, if you want to generate resolvers for a GraphQL application, simply select the GraphQL (code first) (or GraphQL (schema first)) as your transport layer. In this case, NestJS will generate a resolver class instead of a REST API controller.

Hint To avoid generating test files, you can pass the --no-spec flag, as follows: nest g resource users --no-spec

CONCLUSION

resource schematic helps speed up and improve the developer experience tremendously, letting us build our Nest applications that much faster.

CSE engineer on technology hunt.