Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@nestjs/platform-fastify
Advanced tools
Nest - modern, fast, powerful node.js web framework (@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.
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();
@nestjs/platform-express is the default HTTP server adapter for NestJS, using Express as the underlying server. It is more widely used and has a larger ecosystem of middleware and plugins compared to Fastify.
Fastify is a standalone web framework for Node.js that focuses on high performance and low overhead. While it can be used independently, it lacks the built-in structure and features of NestJS, such as dependency injection and modular architecture.
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. It is the most popular web framework for Node.js but does not offer the same level of performance as Fastify.
A progressive Node.js framework for building efficient and scalable server-side applications.
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.
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.
For questions and support please use the official Discord channel. The issue list of this repo is exclusively for bug reports and feature requests.
Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.
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.
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.
Nest is MIT licensed.
FAQs
Nest - modern, fast, powerful node.js web framework (@platform-fastify)
The npm package @nestjs/platform-fastify receives a total of 273,562 weekly downloads. As such, @nestjs/platform-fastify popularity was classified as popular.
We found that @nestjs/platform-fastify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.