Search⌘ K
AI Features

Generating Modules, Controllers, and Services

Explore how to use the NestJS CLI to create modules controllers and services in a backend application. Understand the importance of separating concerns for maintainability and scalability while establishing the foundation of a REST API.

Now that we’ve defined our application requirements and specifications, we’ll use the NestJS CLI to create our project. This lesson will use NestCLI to generate our application’s modules, controllers, and services.

Project creation

Note: This course primarily uses npm for consistency and a seamless learning experience. It’s a widely used package manager in the JavaScript ecosystem.

To create a new project called books-api, run the following command:

nest new books-api

Terminal 1
Terminal
Loading...

Choose npm as a package manager. At the end of project creation, our project folder structure should resemble the following:

books-api/
  ├── node_modules/
  ├── src/
  │   ├── main.ts
  │   ├── app.module.ts
  │   ├── app.controller.ts
  │   ├── app.service.ts
  ├── test/
  ├── .gitignore
  ├── nest-cli.json
  ├── package.json
  ├── package-lock.json
  └── tsconfig.json

Creating BooksModule

Before creating BooksModule ...