Questions tagged [fastify]

Fast and low overhead web framework for Node.js (https://www.fastify.io)

Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture. It is inspired by Hapi and Express.

The official website of Fastify is www.fastify.io. The source can be found on GitHub.

Useful links:

Older versions

671 questions
7
votes
1 answer

What is the exact use of fastify-plugin

I new to fastify framework for node.js, and I'm asking for what is the exact use of fastify-plugin because I can't get the the idea behind it. I tried some code with or without the plugin and I can't notice the difference. except for some behavior…
Momen Nano
  • 109
  • 4
7
votes
1 answer

How to organize routing in fastify?

Forgive me for these heretical speeches, but I consider express to be the best library for api building from the developer experience point of view. But what stops me from using it everywhere is that everyone keeps saying (and confirming with…
muturgan
  • 473
  • 1
  • 8
  • 19
7
votes
1 answer

NestJS set HttpStatus in interceptor

I'm using an interceptor to transform my response. I want to set the HttpStatus inside but the code I'm using now doesn't work. import { CallHandler, ExecutionContext, NestInterceptor, SetMetadata } from '@nestjs/common'; import { Observable } from…
toonvanstrijp
  • 417
  • 1
  • 5
  • 18
6
votes
1 answer

Is there any option to disable playground when in production mode?

Is there any option in apollo v3 to disable playground when inside production mode? in v2 you could disable it by passing playground: false to ApolloServer options but can't find any in v3. Im using apollo-server-fastify. Edit: I have disabled…
Mj Ebrahimzadeh
  • 587
  • 9
  • 22
6
votes
1 answer

ajv-errors plugin with Fastify gives error as Cannot find module 'ajv/dist/compile/codegen'

To give some background, I am trying to add proper schema validation error message formatting (to sugercoat the validation errors) for AJV JSON Schema Validation. I am using Fastify middleware. My purpose is to wrap the default schema error…
Pradip
  • 509
  • 1
  • 5
  • 22
6
votes
2 answers

How to enable fastify's http2 in Digital Ocean app platform

I'm trying to figure out how to enable http2 for my rest api. I uses fastify as its server and according to their documentation secure http2 can be enabled in the following way https://www.fastify.io/docs/latest/Reference/HTTP2/ The issue I am…
Ilja
  • 44,142
  • 92
  • 275
  • 498
6
votes
3 answers

Giving error with node/fastify Unsupported Media Type: application/x-www-form-urlencoded

index.js fastify.get("/paynow", (request, reply) => { let data = { TXN_AMOUNT: '10', // request amount ORDER_ID: 'ORDER_123455', // any unique order id CUST_ID: 'CUST_1238w4' // any unique customer id } // create Paytm…
Shubham Sharma
  • 321
  • 1
  • 6
  • 18
6
votes
1 answer

fastify route request and response handler type in Typescript

Anyone know what is the request and response handler type in fastify? Now I am just using 'any', typescript eslint gave me a warning: fastify.post('/ac', async(req: any , res: any) => {
Alvin
  • 8,219
  • 25
  • 96
  • 177
6
votes
4 answers

How to Type Fastify Request and Reply payloads?

I'm just getting into Fastify with Typescript and really enjoying it. However, I'm trying to figure out if I can type the response payload. I have the response schema for serialization working and that may be sufficient, but I have internally typed…
Blaine Garrett
  • 1,286
  • 15
  • 23
6
votes
0 answers

How to use Fastify strategies as AuthGuards with NestJS?

Fastify has its own package to handle strategies, which is fastify-auth. Among its strategies include fastify-basic-auth and fastify-jwt. NestJS has a wrapper for passport strategies; @nestjs/passport, along with its documentation. I don't think…
yaserso
  • 2,638
  • 5
  • 41
  • 73
6
votes
3 answers

How to send file with fastify & nestjs?

I have the following front end middleware: export class FrontendMiddleware implements NestMiddleware { use(req: any, res: any, next: () => void) { const url = req.originalUrl; if (url.indexOf('rest') === 1) { next(); …
yantrab
  • 2,482
  • 4
  • 31
  • 52
6
votes
4 answers

How to access fastify instance from a handler/controller file?

I need to access the fastify instance from a handler file. I don't remember at all how I should be doing that. index: fastify.register(require('./routes/auth'), { prefix: '/auth' }) routes/auth: module.exports = function(fastify, opts, next) { …
HypeWolf
  • 750
  • 12
  • 29
5
votes
1 answer

ZOD [Error]: Schema with id 'Schema' already declared

I am new to Fastify and Typescript. I am working on adding Zod schemas for validation and I am getting this error: /app/node_modules/fastify/lib/schemas.js:32 throw new FST_ERR_SCH_ALREADY_PRESENT(id) ^ FastifyError [Error]: Schema…
ASR4
  • 545
  • 1
  • 8
  • 24
5
votes
1 answer

What is the order of execution of the same-type hooks in fastify?

In Fastify.js you have at least to ways to register hooks: globally (via fastify.addHook()) or as a property inside the route declaration. In the example below I'm trying to use fastfy-multer to handle file uploading but the maximum amount of files…
Juribiyan
  • 700
  • 8
  • 25
5
votes
0 answers

How I can use sendFile in fastify?

Server.ts import fastify from "fastify"; import cookie from 'fastify-cookie'; import apiRoute from './routes/api'; import jwtPlugin from "./plugins/jwtPlugin"; import closePlugin from "./plugins/closePlugin"; import path from "path"; const PORT =…
Polaris Nation
  • 1,085
  • 2
  • 18
  • 49
1
2
3
44 45