Robust Backends with Nx 7.3 and NestJS

Jason Jean
Nx Devtools
Published in
4 min readJan 8, 2019

--

Nrwl Products: Built By Developers, For Developers.

At Nrwl we set out to build tools to make our lives and our enterprise development team’s work easier when developing applications powered by Angular. Our products help you save time and build better software while getting your team on the same page using the same best practices. Learn more at nrwl.io/products.

Today, we are happy to announce the release of Nx 7.3 which allows developing NestJS applications!

Nrwl Extensions for Angular (aka Nrwl Nx) is an open source toolkit for enterprise applications, which we developed at Nrwl based on our experience working at Google and helping Fortune 500 enterprises build ambitious Angular applications.

In case you are not familiar with it, Nx uses and extends the Angular CLI. You can read this blog post about Nx 6 and explore our recommendations on leveling up with the Angular CLI and Nx.

What is NestJS?

NestJS is a full-fledged framework inspired by Angular for building backends with NodeJS. It provides many of the same benefits that Angular provides. It’s declarative and works well for larger teams.

NestJS and Angular

NestJS and Angular applications have similar architectures.

Controllers

  • Synonymous to components in Angular
  • These assemble responses to return to the requests of users
  • This is where route handling occurs

Providers

  • Synonymous to providers in Angular
  • Providers can be a variety of things: Services, Classes, functions, values, etc.
  • Providers are singletons provided via Dependency Injection(DI) to components or other providers
  • Services are responsible for non-request logic such as fetching data, business logic, logging, etc.

Modules

  • Synonymous to modules in Angular
  • Modules organize controllers and providers into closely related feature sets
  • Modules can import functionality exported by other Modules
  • Each application contains a root module, the starting point of an application bootstrapped by the framework

Some other similarities between NestJS and Angular are the following:

Read more about NestJS in the official NestJS Documentation!

Why use NestJS?

  1. NestJS is a great tool for Angular developers because of its familiarity.
  2. NestJS provides more structure, which helps large teams build complex backends more consistently than when using Express or other minimalistic frameworks.
  3. In many ways, NestJS is also similar to Spring and .NET. So developers familiar with these technologies can use the hard-learned patterns and best practices when using NestJS.
  4. NestJS is platform agnostic and supports REST, GraphQL, Websockets, gRPC, etc.. NestJS code can be reused when supporting multiple technologies or moving to a new technology.

Using NestJS with Nx

In Nx 7.3, we have made using NestJS with an Angular repo extremely easy. Add a NestJS application to an Nx workspace by simply passing nestjs as the framework option when creating a NodeJS application:

ng g node-app nestjs-app --framework nestjs

NestJS applications are developed using the Angular CLI just like other NodeJS or Angular applications:

ng serve nestjs-app
ng build nestjs-app
ng test nestjs-app
ng lint nestjs-app

Getting started with Nx

We encourage you to review our documentation to see how to get started with Nx, whether you have an existing Angular Application or are starting a new project. We hope you find it helpful.

How to Update Nx

Updating Nx can be done with the following commands and will update your dependencies and code to the latest version:

yarn update
# Or for NPM
npm run update

Explore More

A Recap of How Far We Have Come with Nx 7

Building Full-Stack Applications Using Angular CLI and NodeJS

As always, if you’re looking for Angular consulting, training and support, you can find out more about how we work with our clients here.

If you liked this, click the 👏 below so other people will see this here on Medium. Follow Jason Jean and @nrwl_io to read more about Angular.

--

--