Why NestJS
NestJS(we will use Nest often) is a popular framework for building efficient, scalable Node server-side applications. Some reasons why developers might choose NestJS for API development include its use of modern JavaScript and TypeScript, its modular architecture, you don’t have to care much about the architecture of your project since Nest provides modern patterns, and its ability to easily integrate with other common libraries and frameworks such as Express. Additionally, NestJS provides a powerful CLI that can be used to generate boilerplate code, which can be a time-saver, making it easier to get started with building an API. Overall, NestJS can make it easier for developers to build efficient and maintainable APIs in a relatively short amount of time, read more about the fundamental of Nest here.
Apart from what has been mentioned already, Nest has several advantages that make it a popular choice for building server-side applications, including:
- Modular structure: Nest uses a modular architecture, which allows developers to organize their code into reusable modules and components. This makes it easy to build, test, and maintain large-scale applications.
- TypeScript support: built with TypeScript, improves code organization and eliminates the need for manual type rewriting by addressing the challenge of consistent types across server, client, schema, and resolvers.
- Built-in testing support: Nest comes with built-in testing support, making it easy to write and run unit tests for your application.
- Strong performance: Nest uses Express.js under the hood, which means that it is built on a solid foundation and can handle a large number of requests.
- Large and active community: Nest has a large and active community of developers, which means that there are plenty of resources and tutorials available to help you learn and troubleshoot.
- Integrations: Nest easily integrates with other common libraries and frameworks such as Express, MongoDB, and Socket.io, which makes it easy to connect to databases and other services.
In our use case, we are building Graphql API and there are several reasons why Nest is the better choice for us:
- It provides a powerful set of decorators and tools for implementing GraphQL resolvers, making it easy to define and organize the schema for a GraphQL API, that way we don’t have to write all from scratch ourselves, which makes us save countless time.
- It allows you to use GraphQL in a modular way, which makes it easy to organize and test your GraphQL code, which we will see in the second part in practice.
- It also provides the ability to easily integrate with the Apollo Server, which is a popular library for building GraphQL APIs.
Nest's modular architecture and support for GraphQL make it a great choice for building scalable and maintainable GraphQL APIs.
Too much talk, let’s see all of this in practice.