@nestjs/platform-fastify

  • Version 12.1.0
  • Published
  • 133 kB
  • 9 dependencies
  • MIT license

Install

npm i @nestjs/platform-fastify
yarn add @nestjs/platform-fastify
pnpm add @nestjs/platform-fastify

Overview

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

Index

Functions

Classes

Interfaces

Type Aliases

Functions

function AnyFilesInterceptor

AnyFilesInterceptor: (localOptions?: MultipartOptions) => Type<NestInterceptor>;
  • Accepts every file, in any field, and exposes them as an array in req.files (@UploadedFiles()). The Fastify counterpart of platform-express's AnyFilesInterceptor.

    Parameter localOptions

    options merged over the MultipartModule defaults

function diskStorage

diskStorage: (options?: DiskStorageOptions) => MultipartStorageEngine;
  • Writes each file to disk, with multer's diskStorage defaults and file shape (destination, filename, path, size).

function FileFieldsInterceptor

FileFieldsInterceptor: (
uploadFields: MultipartField[],
localOptions?: MultipartOptions
) => Type<NestInterceptor>;
  • Accepts files in each of uploadFields and exposes them grouped by field name in req.files (@UploadedFiles()). The Fastify counterpart of platform-express's FileFieldsInterceptor.

    Parameter uploadFields

    accepted fields, each with an optional maxCount

    Parameter localOptions

    options merged over the MultipartModule defaults

function FileInterceptor

FileInterceptor: (
fieldName: string,
localOptions?: MultipartOptions
) => Type<NestInterceptor>;
  • Accepts a single file in fieldName and exposes it as req.file (@UploadedFile()), with the text fields in req.body. The Fastify counterpart of platform-express's FileInterceptor.

    Requires the @fastify/multipart package, which the FastifyAdapter registers as a plugin when an upload interceptor is used (see its multipart option).

    Parameter fieldName

    name of the form field that carries the file

    Parameter localOptions

    options merged over the MultipartModule defaults

function FilesInterceptor

FilesInterceptor: (
fieldName: string,
maxCount?: number,
localOptions?: MultipartOptions
) => Type<NestInterceptor>;
  • Accepts up to maxCount files in fieldName and exposes them as an array in req.files (@UploadedFiles()). The Fastify counterpart of platform-express's FilesInterceptor.

    Parameter fieldName

    name of the form field that carries the files

    Parameter maxCount

    maximum number of files to accept

    Parameter localOptions

    options merged over the MultipartModule defaults

function FileStreamInterceptor

FileStreamInterceptor: (
fieldName: string,
localOptions?: Omit<MultipartOptions, 'dest' | 'storage'>
) => Type<NestInterceptor>;
  • Hands the route handler a single file in fieldName as a stream (req.file.stream, see MultipartFileStream), without buffering it or writing it to disk. Fastify only; there is no platform-express counterpart.

    - Text fields must precede the file in the form: parts that follow it are not parsed. - Whatever the handler leaves unread is discarded before the response is sent, so that the client can finish uploading. When the handler returns a StreamableFile (which may be the upload itself), it is discarded once the response has been sent instead. So a handler that responds with a StreamableFile of something other than the upload should read the upload first: otherwise, when the connection is not kept alive (Connection: close), Node.js closes it right after the response, and a client still uploading fails with EPIPE / ECONNRESET. - A file in any other field fails the request with a 400. - The file size is unknown up front, so MaxFileSizeValidator does not apply, and neither does FileTypeValidator's magic-number check. - Once limits.fileSize is exceeded, the stream errors with a PayloadTooLargeException.

    Parameter fieldName

    name of the form field that carries the file

    Parameter localOptions

    options merged over the MultipartModule defaults (dest and storage do not apply)

function memoryStorage

memoryStorage: () => MultipartStorageEngine;
  • Buffers each file into file.buffer. The default storage engine, as in multer.

function NoFilesInterceptor

NoFilesInterceptor: (localOptions?: MultipartOptions) => Type<NestInterceptor>;
  • Accepts text fields only (exposed in req.body); any file fails the request with a 400. The Fastify counterpart of platform-express's NoFilesInterceptor.

    Parameter localOptions

    options merged over the MultipartModule defaults

function RouteConfig

RouteConfig: (config: any) => any;

function RouteConstraints

RouteConstraints: (config: RouteShorthandOptions) => any;

function RouteSchema

RouteSchema: (schema: FastifySchema) => any;

Classes

class FastifyAdapter

class FastifyAdapter<
TServer extends RawServerBase = RawServerDefault,
TRawRequest extends FastifyRawRequest<TServer> = FastifyRawRequest<TServer>,
TRawResponse extends RawReplyDefaultExpression<TServer> = RawReplyDefaultExpression<TServer>,
TRequest extends FastifyRequest<
RequestGenericInterface,
TServer,
TRawRequest
> = FastifyRequest<RequestGenericInterface, TServer, TRawRequest>,
TReply extends FastifyReply<
RouteGenericInterface,
TServer,
TRawRequest,
TRawResponse
> = FastifyReply<RouteGenericInterface, TServer, TRawRequest, TRawResponse>,
TInstance extends FastifyInstance<
TServer,
TRawRequest,
TRawResponse
> = FastifyInstance<TServer, TRawRequest, TRawResponse>
> extends AbstractHttpAdapter<TServer, TRequest, TReply> {}

constructor

constructor(instanceOrOptions?: any);

    property instance

    protected readonly instance: FastifyInstance<TServer, TRawRequest, TRawResponse>;

      property isParserRegistered

      readonly isParserRegistered: boolean;

        property logger

        protected readonly logger: Logger;

          method appendHeader

          appendHeader: (response: any, name: string, value: string) => any;

            method applyVersionFilter

            applyVersionFilter: (
            handler: Function,
            version: VersionValue,
            versioningOptions: VersioningOptions
            ) => VersionedRoute<TRequest, TReply>;

              method close

              close: () => Promise<void>;

                method copy

                copy: (
                ...args: any[]
                ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                  method createMiddlewareFactory

                  createMiddlewareFactory: (
                  requestMethod: RequestMethod
                  ) => Promise<(path: string, callback: Function) => any>;

                    method delete

                    delete: (
                    ...args: any[]
                    ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                      method enableCors

                      enableCors: (options?: FastifyCorsOptions) => void;

                        method end

                        end: (response: TReply, message?: string) => void;

                          method get

                          get: (
                          ...args: any[]
                          ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                            method getHeader

                            getHeader: (response: any, name: string) => any;

                              method getHttpServer

                              getHttpServer: <T = TServer>() => T;

                                method getInstance

                                getInstance: <T = TInstance>() => T;

                                  method getRequestHostname

                                  getRequestHostname: (request: TRequest) => string;

                                    method getRequestMethod

                                    getRequestMethod: (request: TRequest) => string;

                                      method getRequestUrl

                                      getRequestUrl: { (request: TRequest): string; (request: TRawRequest): string };

                                        method getType

                                        getType: () => string;

                                          method head

                                          head: (
                                          ...args: any[]
                                          ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                            method init

                                            init: () => Promise<void>;

                                              method initHttpServer

                                              initHttpServer: (options?: NestApplicationOptions) => void;

                                                method inject

                                                inject: {
                                                (): LightMyRequestChain;
                                                (opts: any): Promise<LightMyRequestResponse>;
                                                };

                                                  method isHeadersSent

                                                  isHeadersSent: (response: TReply) => boolean;

                                                    method isRouteOrderSensitive

                                                    isRouteOrderSensitive: () => boolean;

                                                      method listen

                                                      listen: {
                                                      (port: string | number, callback?: () => void): void;
                                                      (port: string | number, hostname: string, callback?: () => void): void;
                                                      };

                                                        method lock

                                                        lock: (
                                                        ...args: any[]
                                                        ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                          method mapException

                                                          mapException: (error: unknown) => unknown;

                                                            method mkcol

                                                            mkcol: (
                                                            ...args: any[]
                                                            ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                              method move

                                                              move: (
                                                              ...args: any[]
                                                              ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                method options

                                                                options: (
                                                                ...args: any[]
                                                                ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                  method patch

                                                                  patch: (
                                                                  ...args: any[]
                                                                  ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                    method post

                                                                    post: (
                                                                    ...args: any[]
                                                                    ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                      method propfind

                                                                      propfind: (
                                                                      ...args: any[]
                                                                      ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                        method proppatch

                                                                        proppatch: (
                                                                        ...args: any[]
                                                                        ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                          method put

                                                                          put: (
                                                                          ...args: any[]
                                                                          ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                            method query

                                                                            query: (
                                                                            ...args: any[]
                                                                            ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                              method redirect

                                                                              redirect: (
                                                                              response: TReply,
                                                                              statusCode: number,
                                                                              url: string
                                                                              ) => FastifyReply<
                                                                              RouteGenericInterface,
                                                                              TServer,
                                                                              TRawRequest,
                                                                              TRawResponse,
                                                                              unknown,
                                                                              any,
                                                                              any,
                                                                              unknown
                                                                              >;

                                                                                method register

                                                                                register: <TRegister extends unknown[]>(
                                                                                plugin: TRegister['0'],
                                                                                opts?: TRegister['1']
                                                                                ) => any;

                                                                                  method registerParserMiddleware

                                                                                  registerParserMiddleware: (prefix?: string, rawBody?: boolean) => void;

                                                                                    method registerSecurityHook

                                                                                    registerSecurityHook: (hook: SecurityRequestHook<TRequest>) => void;
                                                                                    • Runs the request hook of the built-in HTTP security features in an onRequest hook: before middie (Nest middleware), content-type parsing, guards and handlers, and also for unmatched routes. Headers set by the hook go to the Node.js response (reply.raw): Fastify merges them into every response it sends, errors and 404s included, while reply.header() / @Header() values take precedence, and responses written to reply.raw directly (e.g. @Sse()) carry them too. A rejection goes to done(error), i.e. to the Nest exception layer installed with setErrorHandler().

                                                                                    method registerWithPrefix

                                                                                    protected registerWithPrefix: (
                                                                                    factory:
                                                                                    | FastifyPluginCallback<any>
                                                                                    | FastifyPluginAsync<any>
                                                                                    | Promise<{ default: FastifyPluginCallback<any> }>
                                                                                    | Promise<{ default: FastifyPluginAsync<any> }>,
                                                                                    prefix?: string
                                                                                    ) => FastifyInstance<
                                                                                    TServer,
                                                                                    TRawRequest,
                                                                                    TRawResponse,
                                                                                    FastifyBaseLogger,
                                                                                    import('fastify').FastifyTypeProviderDefault
                                                                                    > &
                                                                                    PromiseLike<undefined> & { __linterBrands: 'SafePromiseLike' };

                                                                                      method render

                                                                                      render: (
                                                                                      response: TReply & { view: Function },
                                                                                      view: string,
                                                                                      options: any
                                                                                      ) => FastifyReply<
                                                                                      RouteGenericInterface,
                                                                                      RawServerDefault,
                                                                                      http.IncomingMessage,
                                                                                      http.ServerResponse<http.IncomingMessage>,
                                                                                      unknown,
                                                                                      any,
                                                                                      any,
                                                                                      unknown
                                                                                      >;

                                                                                        method reply

                                                                                        reply: (
                                                                                        response: TRawResponse | TReply,
                                                                                        body: any,
                                                                                        statusCode?: number
                                                                                        ) => FastifyReply<
                                                                                        RouteGenericInterface,
                                                                                        TServer,
                                                                                        TRawRequest,
                                                                                        TRawResponse,
                                                                                        unknown,
                                                                                        any,
                                                                                        any,
                                                                                        unknown
                                                                                        >;

                                                                                          method search

                                                                                          search: (
                                                                                          ...args: any[]
                                                                                          ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                                            method setErrorHandler

                                                                                            setErrorHandler: (
                                                                                            handler: Parameters<TInstance['setErrorHandler']>[0]
                                                                                            ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                                              method setHeader

                                                                                              setHeader: (
                                                                                              response: TReply,
                                                                                              name: string,
                                                                                              value: string
                                                                                              ) => FastifyReply<
                                                                                              RouteGenericInterface,
                                                                                              TServer,
                                                                                              TRawRequest,
                                                                                              TRawResponse,
                                                                                              unknown,
                                                                                              any,
                                                                                              any,
                                                                                              unknown
                                                                                              >;

                                                                                                method setNotFoundHandler

                                                                                                setNotFoundHandler: (
                                                                                                handler: Function
                                                                                                ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                                                  method setOnRequestHook

                                                                                                  setOnRequestHook: (
                                                                                                  hook: (
                                                                                                  request: TRequest,
                                                                                                  reply: TReply,
                                                                                                  done: (err?: Error) => void
                                                                                                  ) => void | Promise<void>
                                                                                                  ) => void;

                                                                                                    method setOnResponseHook

                                                                                                    setOnResponseHook: (
                                                                                                    hook: (
                                                                                                    request: TRequest,
                                                                                                    reply: TReply,
                                                                                                    done: (err?: Error) => void
                                                                                                    ) => void | Promise<void>
                                                                                                    ) => void;

                                                                                                      method setViewEngine

                                                                                                      setViewEngine: (options: FastifyViewOptions | string) => Promise<any>;

                                                                                                        method status

                                                                                                        status: (response: TRawResponse | TReply, statusCode: number) => any;

                                                                                                          method unlock

                                                                                                          unlock: (
                                                                                                          ...args: any[]
                                                                                                          ) => FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, any>;

                                                                                                            method use

                                                                                                            use: (...args: any[]) => any;

                                                                                                              method useBodyParser

                                                                                                              useBodyParser: (
                                                                                                              type: string | string[] | RegExp,
                                                                                                              rawBody: boolean,
                                                                                                              options?: NestFastifyBodyParserOptions,
                                                                                                              parser?: FastifyBodyParser<Buffer, TServer>
                                                                                                              ) => void;

                                                                                                                method useMultipart

                                                                                                                useMultipart: () => void;
                                                                                                                • Registers the "@fastify/multipart" plugin, unless the adapter's multipart option is false, or the plugin has been registered already by the time it loads. Idempotent. Called by the upload interceptors from "@nestjs/platform-fastify/multipart".

                                                                                                                  The plugin is loaded lazily, and a missing package fails the application's startup (ready()) with an error naming the package, rather than exiting the process.

                                                                                                                method useStaticAssets

                                                                                                                useStaticAssets: (options: FastifyStaticOptions) => Promise<any>;

                                                                                                                  class MultipartModule

                                                                                                                  class MultipartModule {}
                                                                                                                  • Provides default options for every upload interceptor in the importing module. The Fastify counterpart of platform-express's MulterModule.

                                                                                                                    It does not configure the @fastify/multipart plugin itself (which the FastifyAdapter registers); pass plugin-wide options through the adapter's multipart option.

                                                                                                                  method register

                                                                                                                  static register: (options?: MultipartModuleOptions) => DynamicModule;

                                                                                                                    method registerAsync

                                                                                                                    static registerAsync: (options: MultipartModuleAsyncOptions) => DynamicModule;

                                                                                                                      Interfaces

                                                                                                                      interface DiskStorageOptions

                                                                                                                      interface DiskStorageOptions {}

                                                                                                                      property destination

                                                                                                                      destination?: string | NameResolver;
                                                                                                                      • The folder files are written to (Default: os.tmpdir()). A string is created when the storage engine is; a function must return a folder that already exists.

                                                                                                                      property filename

                                                                                                                      filename?: NameResolver;
                                                                                                                      • The file name within destination (Default: 32 random hex characters, no extension).

                                                                                                                      interface IncomingMultipartFile

                                                                                                                      interface IncomingMultipartFile {}
                                                                                                                      • What a storage engine and fileFilter see before the file is stored.

                                                                                                                      property encoding

                                                                                                                      encoding: string;
                                                                                                                      • Encoding type of the file

                                                                                                                      property fieldname

                                                                                                                      fieldname: string;
                                                                                                                      • Field name specified in the form

                                                                                                                      property mimetype

                                                                                                                      mimetype: string;
                                                                                                                      • Mime type of the file

                                                                                                                      property originalname

                                                                                                                      originalname: string;
                                                                                                                      • Name of the file on the user's computer

                                                                                                                      property stream

                                                                                                                      readonly stream: Readable;
                                                                                                                      • The file contents. Non-enumerable; meant to be consumed by MultipartStorageEngine._handleFile only.

                                                                                                                      interface MultipartField

                                                                                                                      interface MultipartField {}

                                                                                                                      property maxCount

                                                                                                                      maxCount?: number;
                                                                                                                      • Optional maximum number of files per field to accept.

                                                                                                                      property name

                                                                                                                      name: string;
                                                                                                                      • The field name.

                                                                                                                      interface MultipartFileStream

                                                                                                                      interface MultipartFileStream {}
                                                                                                                      • The file FileStreamInterceptor hands to the route handler. Its size is not known up front.

                                                                                                                      property encoding

                                                                                                                      encoding: string;
                                                                                                                      • Encoding type of the file

                                                                                                                      property fieldname

                                                                                                                      fieldname: string;
                                                                                                                      • Field name specified in the form

                                                                                                                      property mimetype

                                                                                                                      mimetype: string;
                                                                                                                      • Mime type of the file

                                                                                                                      property originalname

                                                                                                                      originalname: string;
                                                                                                                      • Name of the file on the user's computer

                                                                                                                      property stream

                                                                                                                      stream: Readable;
                                                                                                                      • The file contents. Errors with a PayloadTooLargeException once limits.fileSize is exceeded.

                                                                                                                      interface MultipartLimits

                                                                                                                      interface MultipartLimits {}
                                                                                                                      • Same keys as platform-express's MulterLimits.

                                                                                                                        Limits that are not set fall back to the options @fastify/multipart was registered with, and then to its own defaults. Unlike multer (which defaults fileSize and parts to Infinity), @fastify/multipart caps fileSize at the Fastify instance's bodyLimit (1 MiB unless configured) and parts at 1000.

                                                                                                                      property fieldNameSize

                                                                                                                      fieldNameSize?: number;
                                                                                                                      • Max field name size in bytes (Default: unlimited). Unlike the other limits, it does not fall back to the options @fastify/multipart was registered with.

                                                                                                                      property fields

                                                                                                                      fields?: number;
                                                                                                                      • Max number of non-file fields (Default: Infinity)

                                                                                                                      property fieldSize

                                                                                                                      fieldSize?: number;
                                                                                                                      • Max field value size (Default: 1MB)

                                                                                                                      property files

                                                                                                                      files?: number;
                                                                                                                      • For multipart forms, the max number of file fields (Default: Infinity)

                                                                                                                      property fileSize

                                                                                                                      fileSize?: number;
                                                                                                                      • For multipart forms, the max file size in bytes (Default: the Fastify bodyLimit, 1 MiB)

                                                                                                                      property headerPairs

                                                                                                                      headerPairs?: number;
                                                                                                                      • For multipart forms, the max number of header key => value pairs to parse (Default: 2000)

                                                                                                                      property parts

                                                                                                                      parts?: number;
                                                                                                                      • For multipart forms, the max number of parts (fields + files) (Default: 1000)

                                                                                                                      interface MultipartModuleAsyncOptions

                                                                                                                      interface MultipartModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {}

                                                                                                                      property inject

                                                                                                                      inject?: Array<InjectionToken | OptionalFactoryDependency>;

                                                                                                                        property useClass

                                                                                                                        useClass?: Type<MultipartOptionsFactory>;

                                                                                                                          property useExisting

                                                                                                                          useExisting?: Type<MultipartOptionsFactory>;

                                                                                                                            property useFactory

                                                                                                                            useFactory?: (
                                                                                                                            ...args: any[]
                                                                                                                            ) => Promise<MultipartModuleOptions> | MultipartModuleOptions;

                                                                                                                              interface MultipartOptions

                                                                                                                              interface MultipartOptions {}
                                                                                                                              • Same keys and semantics as platform-express's MulterOptions, so option objects can be moved between adapters as-is.

                                                                                                                              property defParamCharset

                                                                                                                              defParamCharset?: string;
                                                                                                                              • Default character set for part header values (e.g. filename) (Default: 'latin1')

                                                                                                                              property dest

                                                                                                                              dest?: string;
                                                                                                                              • Where to store the files (disk storage). Ignored when storage is set.

                                                                                                                              property limits

                                                                                                                              limits?: MultipartLimits | ((req: any) => MultipartLimits);
                                                                                                                              • An object specifying the size limits, or a function of the request that returns one. Merged over the limits @fastify/multipart was registered with.

                                                                                                                              property preservePath

                                                                                                                              preservePath?: boolean;
                                                                                                                              • Keep the full path of files instead of just the base name (Default: false)

                                                                                                                              property storage

                                                                                                                              storage?: MultipartStorageEngine;
                                                                                                                              • The storage engine to use for uploaded files (Default: memory storage).

                                                                                                                              method fileFilter

                                                                                                                              fileFilter: (
                                                                                                                              req: any,
                                                                                                                              file: IncomingMultipartFile,
                                                                                                                              callback: (error: Error | null, acceptFile: boolean) => void
                                                                                                                              ) => void;
                                                                                                                              • Decides which files are stored. Call callback(null, false) to skip a file, or callback(error, false) to fail the request with error.

                                                                                                                              interface MultipartOptionsFactory

                                                                                                                              interface MultipartOptionsFactory {}

                                                                                                                              method createMultipartOptions

                                                                                                                              createMultipartOptions: () =>
                                                                                                                              | Promise<MultipartModuleOptions>
                                                                                                                              | MultipartModuleOptions;

                                                                                                                                interface MultipartStorageEngine

                                                                                                                                interface MultipartStorageEngine {}
                                                                                                                                • multer's storage engine contract (_handleFile / _removeFile), kept as-is so existing multer storage engines can be passed as storage.

                                                                                                                                interface NestFastifyApplication

                                                                                                                                interface NestFastifyApplication<TServer extends RawServerBase = RawServerDefault>
                                                                                                                                extends INestApplication<TServer> {}

                                                                                                                                method enableCors

                                                                                                                                enableCors: (options?: FastifyCorsOptions) => void;
                                                                                                                                • Enables CORS (Cross-Origin Resource Sharing)

                                                                                                                                  Returns

                                                                                                                                  {void}

                                                                                                                                method getHttpAdapter

                                                                                                                                getHttpAdapter: () => HttpServer<FastifyRequest, FastifyReply, FastifyInstance>;
                                                                                                                                • Returns the underlying HTTP adapter bounded to a Fastify app.

                                                                                                                                  Returns

                                                                                                                                  {HttpServer}

                                                                                                                                method inject

                                                                                                                                inject: {
                                                                                                                                (): LightMyRequestChain;
                                                                                                                                (opts: any): Promise<LightMyRequestResponse>;
                                                                                                                                };
                                                                                                                                • A wrapper function around native fastify.inject() method.

                                                                                                                                  Returns

                                                                                                                                  {void}

                                                                                                                                method listen

                                                                                                                                listen: {
                                                                                                                                (
                                                                                                                                opts: FastifyListenOptions,
                                                                                                                                callback?: (err: Error | null, address: string) => void
                                                                                                                                ): Promise<TServer>;
                                                                                                                                (opts?: FastifyListenOptions): Promise<TServer>;
                                                                                                                                (callback?: (err: Error, address: string) => void): Promise<TServer>;
                                                                                                                                (
                                                                                                                                port: string | number,
                                                                                                                                callback?: (err: Error, address: string) => void
                                                                                                                                ): Promise<TServer>;
                                                                                                                                (
                                                                                                                                port: string | number,
                                                                                                                                address: string,
                                                                                                                                callback?: (err: Error, address: string) => void
                                                                                                                                ): Promise<TServer>;
                                                                                                                                (
                                                                                                                                port: string | number,
                                                                                                                                address: string,
                                                                                                                                backlog: number,
                                                                                                                                callback?: (err: Error, address: string) => void
                                                                                                                                ): Promise<TServer>;
                                                                                                                                };
                                                                                                                                • Starts the application.

                                                                                                                                  Returns

                                                                                                                                  A Promise that, when resolved, is a reference to the underlying HttpServer.

                                                                                                                                method register

                                                                                                                                register: <Options extends FastifyPluginOptions = any>(
                                                                                                                                plugin:
                                                                                                                                | FastifyPluginCallback<Options>
                                                                                                                                | FastifyPluginAsync<Options>
                                                                                                                                | Promise<{ default: FastifyPluginCallback<Options> }>
                                                                                                                                | Promise<{ default: FastifyPluginAsync<Options> }>,
                                                                                                                                opts?: FastifyRegisterOptions<Options>
                                                                                                                                ) => Promise<FastifyInstance>;
                                                                                                                                • A wrapper function around native fastify.register() method. Example `app.register(require('@fastify/formbody'))

                                                                                                                                  Returns

                                                                                                                                  {Promise}

                                                                                                                                method setViewEngine

                                                                                                                                setViewEngine: (options: FastifyViewOptions | string) => this;
                                                                                                                                • Sets a view engine for templates (views), for example: pug, handlebars, or ejs.

                                                                                                                                  Don't pass in a string. The string type in the argument is for compatibility reason and will cause an exception.

                                                                                                                                  Returns

                                                                                                                                  {this}

                                                                                                                                method useBodyParser

                                                                                                                                useBodyParser: <TServer extends RawServerBase = RawServerBase>(
                                                                                                                                type: string | string[] | RegExp,
                                                                                                                                options?: NestFastifyBodyParserOptions,
                                                                                                                                parser?: FastifyBodyParser<Buffer, TServer>
                                                                                                                                ) => this;
                                                                                                                                • Register Fastify body parsers on the fly. Will respect the application's rawBody option.

                                                                                                                                  Returns

                                                                                                                                  {this}

                                                                                                                                  Example 1

                                                                                                                                  const app = await NestFactory.create( AppModule, new FastifyAdapter(), { rawBody: true } ); // enable the json parser with a parser limit of 50mb app.useBodyParser('application/json', { bodyLimit: 50 * 1000 * 1024 });

                                                                                                                                method useStaticAssets

                                                                                                                                useStaticAssets: (options: FastifyStaticOptions) => this;
                                                                                                                                • Sets a base directory for public assets. Example app.useStaticAssets({ root: 'public' })

                                                                                                                                  Returns

                                                                                                                                  {this}

                                                                                                                                interface UploadedMultipartFile

                                                                                                                                interface UploadedMultipartFile {}
                                                                                                                                • A stored upload, in the shape multer produces (Express.Multer.File), so @UploadedFile(), ParseFilePipe and the built-in file validators work unchanged. Memory storage sets buffer; disk storage sets destination, filename and path.

                                                                                                                                property buffer

                                                                                                                                buffer?: Buffer;
                                                                                                                                • A Buffer of the entire file (memory storage)

                                                                                                                                property destination

                                                                                                                                destination?: string;
                                                                                                                                • The folder to which the file has been saved (disk storage)

                                                                                                                                property encoding

                                                                                                                                encoding: string;
                                                                                                                                • Encoding type of the file

                                                                                                                                property fieldname

                                                                                                                                fieldname: string;
                                                                                                                                • Field name specified in the form

                                                                                                                                property filename

                                                                                                                                filename?: string;
                                                                                                                                • The name of the file within the destination (disk storage)

                                                                                                                                property mimetype

                                                                                                                                mimetype: string;
                                                                                                                                • Mime type of the file

                                                                                                                                property originalname

                                                                                                                                originalname: string;
                                                                                                                                • Name of the file on the user's computer

                                                                                                                                property path

                                                                                                                                path?: string;
                                                                                                                                • Location of the uploaded file (disk storage)

                                                                                                                                property size

                                                                                                                                size: number;
                                                                                                                                • Size of the file in bytes

                                                                                                                                Type Aliases

                                                                                                                                type MultipartModuleOptions

                                                                                                                                type MultipartModuleOptions = MultipartOptions;

                                                                                                                                  type NestFastifyBodyParserOptions

                                                                                                                                  type NestFastifyBodyParserOptions = Omit<
                                                                                                                                  Parameters<AddContentTypeParser>[1],
                                                                                                                                  'parseAs'
                                                                                                                                  >;

                                                                                                                                    Package Files (19)

                                                                                                                                    Dependencies (9)

                                                                                                                                    Dev Dependencies (0)

                                                                                                                                    No dev dependencies.

                                                                                                                                    Peer Dependencies (5)

                                                                                                                                    Badge

                                                                                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@nestjs/platform-fastify.

                                                                                                                                    • Markdown
                                                                                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@nestjs/platform-fastify)
                                                                                                                                    • HTML
                                                                                                                                      <a href="https://www.jsdocs.io/package/@nestjs/platform-fastify"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>