Socket
Socket
Sign inDemoInstall

@nestjs/common

Package Overview
Dependencies
11
Maintainers
1
Versions
356
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs/common

Nest - modern, fast, powerful node.js web framework (@common)


Version published
Maintainers
1
Weekly downloads
3,089,152
decreased by-6.75%

Weekly downloads

Package description

What is @nestjs/common?

The @nestjs/common package is a core part of the NestJS framework, which is a framework for building efficient, reliable and scalable server-side applications. This package provides a wide range of basic functionalities necessary for any NestJS application, including decorators, modules, middleware, filters, pipes, guards, and utilities for handling HTTP requests and responses.

What are @nestjs/common's main functionalities?

Decorators

Decorators are used to annotate classes and their members to define their roles within the application. For example, `@Injectable()` marks a class as a service that can be injected, and `@Controller()` defines a class as a controller with a specific route.

@Injectable()
class MyService {}

@Controller('my-route')
class MyController {
  constructor(private myService: MyService) {}
}

Modules

Modules are used to organize components by encapsulating them within bounded contexts. This code sample demonstrates how to define a module that includes controllers and providers.

@Module({
  imports: [],
  controllers: [MyController],
  providers: [MyService],
})
class MyModule {}

Middleware

Middleware are functions that execute during the request-response cycle. They can perform tasks like logging, request validation, etc. This code sample shows a basic middleware that logs a message on each request.

@Injectable()
class MyMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    console.log('Request...');
    next();
  }
}

Exception Filters

Exception filters handle exceptions that occur during the processing of a request. This code sample demonstrates a filter that catches HTTP exceptions and formats the response.

@Catch(HttpException)
class HttpExceptionFilter implements ExceptionFilter {
  catch(exception: HttpException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const response = ctx.getResponse<Response>();
    const status = exception.getStatus();

    response
      .status(status)
      .json({
        statusCode: status,
        timestamp: new Date().toISOString(),
        path: ctx.getRequest<Request>().url,
      });
  }
}

Other packages similar to @nestjs/common

Readme

Source

Nest Logo

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

NPM Version Package License NPM Downloads CircleCI Discord Backers on Open Collective Sponsors on Open Collective Support us

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.

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, and 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, and loosely coupled and easily maintainable applications. The architecture is heavily inspired by Angular.

Getting started

Questions

For questions and support please use the official Discord channel. The issue list of this repo is exclusively for bug reports and feature requests.

Issues

Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.

Consulting

With official support, you can get expert help straight from Nest core team. We provide dedicated technical support, migration strategies, advice on best practices (and design decisions), PR reviews, and team augmentation. Read more about support here.

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support from the amazing backers. If you'd like to join them, please read more here.

Principal Sponsors
Gold Sponsors
Silver Sponsors
Sponsors

Backers

Stay in touch

License

Nest is MIT licensed.

FAQs

Last updated on 28 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc