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
22
votes
4 answers

how to use optional url parameters with NestjS

I'm trying to replace our current backend service using Nestjs library, however, I want to create a route with 2 optional parameters in the URL something like : /route/:param1/config/:OptionalParam3?/:OptionalParam3? that means the route should…
Shchori
  • 233
  • 1
  • 2
  • 5
20
votes
4 answers

How can I set a header field in a response with NestJS?

I'm trying: @Post('login') async login(@Body() body: AuthDto, @Res() res: Response) { const loginResponse = await this.authService.login(body); console.log('loginResponse', loginResponse) …
Shamoon
  • 41,293
  • 91
  • 306
  • 570
20
votes
3 answers

How to use TypeScript with Sequelize

I already have my server application written in Node, PostgreSQL, Sequelize using Fastify. Now I would like to use TypeScript. Can anyone tell me how to begin rewriting my Server application using TypeScript.
Rafael
  • 499
  • 1
  • 3
  • 12
15
votes
4 answers

How to assign routes within a base route in fastify

I am using fastify as a web framework in my nodejs project. I want to call all my routes from a directory having a base route defined in main JS file like we do in express. I have read many blogs but i did not find any relevant answer to my…
ADITYA HAZARIKA
  • 300
  • 1
  • 4
  • 13
14
votes
3 answers

Fastify not working on Docker / Kubernetes

I have very simple app that returns "Hello World" string, it works fine locally. As you will see from app code below it runs on port 4000. When I create docker image and run a container, I can't access it from localhost:4000 on my machine, but I can…
Ilja
  • 44,142
  • 92
  • 275
  • 498
14
votes
1 answer

File uploads with graphql-upload, apollo-server-fastify, and the NestJS code first approach

What is the correct implementation for receiving file uploads from a client on a server utilizing the following combination of packages/techniques (and their corresponding dependencies not listed):…
jengel
  • 323
  • 4
  • 10
13
votes
4 answers

In NestJS is there any way to pass data from Guards to the controller?

So I am currently using NestJS extensively in my organization. And for authentication purposes we are using our own guards. So my question is that can anyone please guide me if there any way to pass data from guard to the controller, other than…
Agnibha
  • 613
  • 1
  • 11
  • 20
10
votes
2 answers

Fastify Typescript request query

I'm trying to put together a simple endpoint following the Fastify with Typescript docs here: https://www.fastify.io/docs/v3.1.x/TypeScript/ export default async function foo(fastify: any) { const MyInstance = new Foo(fastify.db); …
Aakshaye
  • 359
  • 1
  • 3
  • 17
10
votes
2 answers

How can i use custom logger in fastify?

My company have a custom developed logger package, and we want to use that as default logger in fastify. I tried to understand how to register my logger with this simple example below, but fastify always use Pino. index.js const log =…
d-t
  • 153
  • 1
  • 1
  • 10
9
votes
1 answer

How I can config logger file in Fastify which created from fastifify cli

I generated fastify project from fastify cli then I really want to use the logger system and write it into the file The code below is the way I try but when I send the request it does not write any log file yet and the system does not create any…
MaiChinu
  • 103
  • 4
9
votes
2 answers

How to use fastify-cors to enable just one api to cross domain?

I want to let [POST] localhost/product just this API to cross-domain. I don't know how to do it fastify.register(require('fastify-cors'), { origin:'*', methods:['POST'], }) this is my API: { method: 'POST', url: '/product', …
radiorz
  • 1,459
  • 4
  • 18
  • 36
9
votes
2 answers

How to parse querystring parameter from URL in Fastify server?

I am a totally new to fastify but I have a fastify server running. I want to parse query string such as: http://fake.com/?user=123&name=ali I want to get "user" and "name" values from the URL above. My current code is like this: fastify.route({ …
8
votes
2 answers

How to get handler route in NestJS Interceptor (For both Express and Fastify)

I am having issues trying to get a hold of the NestJS handler's route in an interceptor I am writing. For instance, if a Controller had a route as such: @Get('/params/:p1/:p2') routeWithParams(@Param() params): string { return `params are…
SomeAnonGuy
  • 256
  • 2
  • 6
8
votes
2 answers

Fastify route not working with specific url

I have this router in my code fastify.get('/:link', (req, reply) => { req.params.url = req.host+req.url; reply.view("template.ejs",req.params); }); I am trying to catch URLs and handle them in the template. The URLs are all…
painor
  • 1,119
  • 1
  • 8
  • 25
7
votes
1 answer

How do I return a file-stream from buffer?

I have stored my image, it's size in bytes and its type on a mysql db. When I fetch it I am getting back a buffer for the image and now Im trying to figure out how to send it back to my client so that it renders the image? Code inside of my…
ThunD3eR
  • 3,216
  • 5
  • 50
  • 94
1
2 3
44 45