What is @nestjs/core?
The @nestjs/core package is the core foundation of the NestJS framework, a framework for building efficient, reliable and scalable server-side applications. It provides out-of-the-box application architecture which allows developers and teams to create highly testable, scalable, loosely coupled, and easily maintainable applications.
What are @nestjs/core's main functionalities?
Module System
NestJS uses a module system to organize code into separate modules. This code sample demonstrates how to define a basic module in NestJS.
import { Module } from '@nestjs/common';
@Module({
imports: [],
controllers: [],
providers: [],
})
export class AppModule {}
Dependency Injection
NestJS provides a powerful dependency injection system, allowing classes to define their dependencies through the constructor. This code sample shows how to inject a service into another.
import { Injectable } from '@nestjs/common';
@Injectable()
export class MyService {
constructor(private otherService: OtherService) {}
}
Controllers and Routing
NestJS allows for easy setup of controllers and routing. This code sample demonstrates defining a controller with a single route that returns a simple string.
import { Controller, Get } from '@nestjs/common';
@Controller('my-route')
export class MyController {
@Get()
getHello(): string {
return 'Hello World!';
}
}
Other packages similar to @nestjs/core
express
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. While it is less opinionated than NestJS, requiring more manual setup for structure and architecture, it serves as the underlying HTTP server framework for NestJS.
fastify
Fastify is a fast and low overhead web framework for Node.js. It is designed to be as efficient and fast as possible, similar to Express but with a focus on speed and performance. NestJS can use Fastify as an alternative HTTP server to Express, offering developers a choice based on their performance needs.
hapi
Hapi is a rich framework for building applications and services, offering a powerful plugin system. It is designed to be more configurable and extensible than Express, providing a robust set of features out of the box. While it shares some similarities with NestJS in terms of offering a structured approach to application development, it does not enforce a specific architecture or dependency injection system.
A progressive Node.js framework for building efficient and scalable web applications. :cat:
Description
Nest is a framework for building efficient, scalable Node.js web applications. It uses modern JavaScript, is built with TypeScript (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Progamming), FP (Functional Programming), and FRP (Functional Reactive Programming).
Under the hood, Nest makes use of Express, allowing for easy use of the myriad third-party plugins which are available.
Philosophy
In recent years, thanks to Node.js, JavaScript has become the “lingua franca” of the web for both front and backend applications, giving rise to awesome projects like Angular, React and Vue which improve developer productivity and enable the construction of fast, testable, extensible frontend applications. However, on the server-side, while there are a lot of superb libraries, helpers and tools for Node, none of them effectively solve the main problem - the architecture.
Nest aims to provide an application architecture out of the box which allows for effortless creation of highly testable, scalable, loosely coupled and easily maintainable applications.
Features
- Built with TypeScript (compatible with pure JavaScript + Babel)
- Easy to learn - syntax similar to Angular
- Familiar - based on well-known libraries (Express / socket.io)
- Dependency Injection - built-in asynchronous IoC container with a hierarchical injector
- WebSockets module (based on socket.io, but you can bring your own library, by making use of
WsAdapter
) - Modular - defines an easy to follow module definition pattern so you can split your system into reusable modules
- Reactive microservice support with message patterns (built-in transport via TCP / Redis, but other communication schemes can be implemented with
CustomTransportStrategy
) - Exception layer - throwable web exceptions with status codes, exception filters
- Pipes - synchronous & asynchronous (e.g. validation purposes)
- Guards - attach additional logic in a declarative manner (e.g. role-based access control)
- Interceptors - built on top of RxJS
- Testing utilities (both e2e & unit tests)
Installation
Install the TypeScript Starter Project with Git:
$ git clone https://github.com/nestjs/typescript-starter.git project
$ cd project
$ npm install
$ npm run start
Install the JavaScript (Babel) Starter Project with Git:
$ git clone https://github.com/nestjs/javascript-starter.git project
$ cd project
$ npm install
$ npm run start
Start a New Project from Scratch with NPM:
$ npm i --save @nestjs/core @nestjs/common @nestjs/microservices @nestjs/websockets @nestjs/testing reflect-metadata rxjs
Documentation & Quick Start
:books: Documentation & Tutorial
Backers
I am on a mission to provide an architecture to create truly flexible, scalable and loosely coupled systems using the Node.js platform. It takes a lot of time, so if you want to support me, please become a backer / sponsor. I appreciate your help. Thanks! :heart_eyes:
People
License
MIT