All sections from NestJS Basics course on CodeSignal
Welcome to your course on building your first NestJS application. This lesson will get you familiar with NestJS and its project structure. As we embark on this journey, we'll dive into the basics of NestJS — a framework designed for building efficient and scalable server-side applications. Unlike other frameworks like Express.js or Koa, NestJS leverages TypeScript and a modular architecture, making it not only easy to use but also highly maintainable and scalable. At the same time, NestJS uses Express.js under the hood (by default).
NestJS is a progressive Node.js framework for building efficient and scalable server-side applications. It uses modern JavaScript, is built with TypeScript (preserving compatibility with plain JavaScript), and combines elements of Object-Oriented Programming (OOP), Functional Programming (FP), and Functional Reactive Programming (FRP). NestJS is inspired by Angular.js so if you are familiar with Angular.js, a lot of these concepts will feel familiar.
Express.js by default but even that is configurable to use something else like Fastify.To bootstrap a sample NestJS project, you can use the NestJS CLI. You can see the installation instruction in the official NestJS documentation. After NestJS CLI is installed on your machine, you can use the following command to create a new project:
npm i -g @nestjs/cli
nest new project-nameWhen you create a new NestJS project using NestJS CLI, various files and directories are automatically generated. Let's break down the key components:
app.controller.ts: Controllers handle incoming requests and return responses to the client. This file contains a basic example of a controller.app.service.ts: Services are used to handle business logic. This file contains a simple service that returns a "Hello World!" message.app.module.ts: This is the root module of your application. It defines how your app is organized by configuring modules, controllers, and providers.
root module that is called AppModulemain.ts: This file is the entry point of your application, responsible for bootstrapping the app.