NestJS Framework

repository·master·Indexed 13 days ago

https://github.com/nestjs/nest

A progressive Node.js framework for building efficient, scalable, and maintainable server-side applications. Built with TypeScript and inspired by Angular, NestJS provides a structured architecture leveraging OOP, FP, and FRP. It is platform-agnostic, supporting Express by default with the ability to switch to Fastify.

Tokens
45.1K
Snippets
134
Records
230
Agent score
97%

What's inside NestJS

  1. Overview of NestJS

    master

    Nest is a progressive Node.js framework designed for building efficient, scalable, and maintainable server-side applications. It is built with TypeScript (while maintaining compatibility with pure JavaScript) and leverages principles from Object-Oriented Programming (OOP), Functional Programming (FP), and Functional Reactive Programming (FRP).

    Key architectural features:

    • Architecture-First: Unlike many Node.js libraries that focus on individual utilities, Nest provides a complete application architecture out of the box, heavily inspired by Angular.
    • Underlying Engine: By default, Nest uses Express, but it is designed to be platform-agnostic and can easily switch to other libraries like Fastify.
    • Scalability: The framework is designed to help developers create highly testable, loosely coupled, and easily maintainable applications.
  2. What is NestJS?

    master

    NestJS is a progressive Node.js framework designed for building efficient and scalable server-side applications. It is heavily inspired by Angular and leverages modern JavaScript or TypeScript.

    Key characteristics include:

    • Programming Paradigms: Combines elements of Object-Oriented Programming (OOP), Functional Programming (FP), and Functional Reactive Programming (FRP).
    • Underlying HTTP Engine: By default, Nest uses Express, but it is designed to be platform-agnostic and provides compatibility with other libraries like Fastify, allowing you to easily use various third-party plugins.
  3. How NestJS approaches architecture

    master

    NestJS aims to enable the immediate construction of practical architectures. The framework is designed to help developers build applications that are:

    • Test-friendly
    • Scalable
    • Loosely coupled
    • Easy to operate

    The architecture is inspired by Angular.

  4. How NestJS approaches application architecture

    master

    Nest aims to solve the architectural challenges often found in Node.js development. Its primary goal is to provide an application architecture that is:

    • Test-friendly
    • Scalable
    • Loosely coupled
    • Easy to maintain

    The architecture is heavily inspired by Angular.

  5. NestJS Design Philosophy

    master

    While many Node.js libraries and tools exist, they often fail to address the core issue of application architecture.

    Nest's primary goal is to provide an out-of-the-box application architecture. This architecture enables developers to easily create applications that are:

    • Highly testable
    • Scalable
    • Loosely coupled
    • Easy to maintain
  6. Setup the Prisma GraphQL schema-first sample

    master

    This sample project demonstrates a schema-first GraphQL implementation using NestJS and Prisma with a SQLite database.

    To get the project running, follow these steps:

    1. Install dependencies: Run npm install to install all required packages.
    2. Generate GraphQL typings: Run npm run generate:typings to create the TypeScript type definitions based on your GraphQL schema.
    3. Initialize the database: Run npx prisma db push to create the SQLite database and sync the schema with the database tables.
    4. Start the development server: Run npm run start:dev to launch the application.

    Note: This sample uses SQLite. If you wish to use a different database provider, refer to the Prisma documentation.

    npm install
    npm run generate:typings
    npx prisma db push
    npm run start:dev
  7. Execute a GraphQL Federation Schema First example

    master

    To run this GraphQL Federation example using the Schema First approach, you must start the sub-graph applications before starting the gateway. This ensures the gateway can successfully fetch the schemas from the sub-graphs during startup.

    Follow these steps in order:

    1. Start the users-application sub-graph.
    2. Start the posts-application sub-graph.
    3. Start the gateway application.
    # 1. Start users sub-graph
    cd users-application && npm run start
    
    # 2. Start posts sub-graph
    cd posts-application && npm run start
    
    # 3. Start gateway
    cd gateway && npm run start
  8. Set up the database for the Sequelize sample

    master

    The Sequelize sample requires a MySQL database. You can use Docker for an automated setup or a local MySQL installation.

    Using Docker

    Use the provided docker-compose.yml file to start the database container:

    docker-compose up

    To stop the container, run:

    docker-compose down

    Using a local MySQL installation

    If you are using a local MySQL instance instead of Docker, you must manually configure the database credentials. Check app.module.ts in the source code to find the required credentials and ensure they match your local database configuration.