Nest JS

Table of Contents

NestJS

A progressive Node.js framework for building efficient, reliable and scalable server-side applications.

I have been developing projects using JS, Typescript actually. I started with React and then NextJS. Now I am interested in Backend.

Description:

Nest is a framework for building efficient, scalable Node.js server-side applications. It uses modern JavaScript, is built with

  • TypeScript (preserves compatibility with pure JavaScript) and
  • combines elements of OOP (Object Oriented Programming),
  • FP (Functional Programming), and
  • FRP (Functional Reactive Programming).

Under the hood, Nest makes use of Express, but also provides compatibility with a wide range of other libraries, like Fastify, allowing for easy use of the myriad of third-party plugins which are available.

Nest aims to provide an application architecture out of the box which allows for effortless creation of

  • highly testable,
  • scalable, and
  • loosely coupled and
  • easily maintainable applications.

The architecture is heavily inspired by Angular.

The docs

Getting started:

Installation:

$ npm i -g @nestjs/cli
$ nest new project-name

It will ask to select the package manager to use.

✔ Installation in progress... ☕

🚀  Successfully created project hello-world
👉  Get started with the following commands:

$ cd hello-world
$ yarn run start

                                         
                          Thanks for installing Nest 🙏
                 Please consider donating to our open collective
                        to help us maintain this package.
                                         
                                         
               🍷  Donate: https://opencollective.com/nest
                                         

For offline:

$ yarn --offline run start 

Compile and run the project

# development
$ yarn run start

# watch mode
$ yarn run start:dev

# production mode
$ yarn run start:prod

Run tests

# unit tests
$ yarn run test

# e2e tests
$ yarn run test:e2e

# test coverage
$ yarn run test:cov

Open your browser and navigate to http://localhost:3000/.

This should show “Hello World!” in frontend.

"dependencies": {
    "@nestjs/common": "^10.0.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/platform-express": "^10.0.0",
    "reflect-metadata": "^0.2.0",
    "rxjs": "^7.8.1"
  }
  "devDependencies": {
    "@nestjs/cli": "^10.0.0",
    "@nestjs/schematics": "^10.0.0",
    "@nestjs/testing": "^10.0.0",
    "@types/express": "^5.0.0",
    "@types/jest": "^29.5.2",
    "@types/node": "^20.3.1",
    "@types/supertest": "^6.0.0",
    "@typescript-eslint/eslint-plugin": "^8.0.0",
    "@typescript-eslint/parser": "^8.0.0",
    "eslint": "^8.0.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.0",
    "jest": "^29.5.0",
    "prettier": "^3.0.0",
    "source-map-support": "^0.5.21",
    "supertest": "^7.0.0",
    "ts-jest": "^29.1.0",
    "ts-loader": "^9.4.3",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.1.3"
  }

The basic boilerplate has:

  1. Typesript
  2. Jest for Testing

So, the meat of the project!

main –> module(App module) –> controller(AppController), provider(AppService)

controller: routes

provider: functions in routes

Tags :