Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nestjs/platform-fastify

Package Overview
Dependencies
Maintainers
2
Versions
249
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs/platform-fastify

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

  • 10.4.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
329K
increased by1.1%
Maintainers
2
Weekly downloads
 
Created

What is @nestjs/platform-fastify?

@nestjs/platform-fastify is an adapter package for the NestJS framework that allows you to use Fastify as the underlying HTTP server instead of the default Express. Fastify is known for its high performance and low overhead, making it a good choice for applications that require high throughput and low latency.

What are @nestjs/platform-fastify's main functionalities?

Basic Setup

This code demonstrates how to set up a basic NestJS application using Fastify as the HTTP server. The `FastifyAdapter` is passed to the `NestFactory.create` method to initialize the application with Fastify.

const { NestFactory } = require('@nestjs/core');
const { FastifyAdapter } = require('@nestjs/platform-fastify');
const { AppModule } = require('./app.module');

async function bootstrap() {
  const app = await NestFactory.create(AppModule, new FastifyAdapter());
  await app.listen(3000);
}
bootstrap();

Middleware Integration

This code shows how to integrate middleware in a NestJS application using Fastify. The `app.use` method is used to add a middleware function that logs each incoming request.

const { NestFactory } = require('@nestjs/core');
const { FastifyAdapter } = require('@nestjs/platform-fastify');
const { AppModule } = require('./app.module');

async function bootstrap() {
  const app = await NestFactory.create(AppModule, new FastifyAdapter());
  app.use((req, res, next) => {
    console.log('Request...');
    next();
  });
  await app.listen(3000);
}
bootstrap();

Route Handling

This code demonstrates how to define a simple route in a NestJS application using Fastify. The `ExampleController` class defines a route that responds with 'Hello, Fastify!' when accessed via a GET request.

const { Controller, Get } = require('@nestjs/common');

@Controller('example')
class ExampleController {
  @Get()
  getExample() {
    return 'Hello, Fastify!';
  }
}

const { NestFactory } = require('@nestjs/core');
const { FastifyAdapter } = require('@nestjs/platform-fastify');
const { AppModule } = require('./app.module');

async function bootstrap() {
  const app = await NestFactory.create(AppModule, new FastifyAdapter());
  await app.listen(3000);
}
bootstrap();

Other packages similar to @nestjs/platform-fastify

FAQs

Package last updated on 15 Nov 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc