@nestjs/platform-express

  • Version 10.3.3
  • Published
  • 62.2 kB
  • 5 dependencies
  • MIT license

Install

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

Overview

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

Index

Functions

function AnyFilesInterceptor

AnyFilesInterceptor: (localOptions?: MulterOptions) => Type<NestInterceptor>;
  • Parameter localOptions

function FileFieldsInterceptor

FileFieldsInterceptor: (
uploadFields: MulterField[],
localOptions?: MulterOptions
) => Type<NestInterceptor>;
  • Parameter uploadFields

    Parameter localOptions

function FileInterceptor

FileInterceptor: (
fieldName: string,
localOptions?: MulterOptions
) => Type<NestInterceptor>;
  • Parameter fieldName

    Parameter localOptions

function FilesInterceptor

FilesInterceptor: (
fieldName: string,
maxCount?: number,
localOptions?: MulterOptions
) => Type<NestInterceptor>;
  • Parameter fieldName

    Parameter maxCount

    Parameter localOptions

function NoFilesInterceptor

NoFilesInterceptor: (localOptions?: MulterOptions) => Type<NestInterceptor>;
  • Parameter localOptions

Classes

class ExpressAdapter

class ExpressAdapter extends AbstractHttpAdapter<http.Server | https.Server> {}

constructor

constructor(instance?: any);

    method appendHeader

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

      method applyVersionFilter

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

        method close

        close: () => Promise<unknown>;

          method createMiddlewareFactory

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

            method disable

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

              method enable

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

                method enableCors

                enableCors: (options: CorsOptions | CorsOptionsDelegate<any>) => any;

                  method end

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

                    method engine

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

                      method getHeader

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

                        method getRequestHostname

                        getRequestHostname: (request: any) => string;

                          method getRequestMethod

                          getRequestMethod: (request: any) => string;

                            method getRequestUrl

                            getRequestUrl: (request: any) => string;

                              method getType

                              getType: () => string;

                                method initHttpServer

                                initHttpServer: (options: NestApplicationOptions) => void;

                                  method isHeadersSent

                                  isHeadersSent: (response: any) => boolean;

                                    method listen

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

                                      method redirect

                                      redirect: (response: any, statusCode: number, url: string) => any;

                                        method registerParserMiddleware

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

                                          method render

                                          render: (response: any, view: string, options: any) => any;

                                            method reply

                                            reply: (response: any, body: any, statusCode?: number) => any;

                                              method set

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

                                                method setBaseViewsDir

                                                setBaseViewsDir: (path: string | string[]) => any;

                                                  method setErrorHandler

                                                  setErrorHandler: (handler: Function, prefix?: string) => any;

                                                    method setHeader

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

                                                      method setLocal

                                                      setLocal: (key: string, value: any) => this;

                                                        method setNotFoundHandler

                                                        setNotFoundHandler: (handler: Function, prefix?: string) => any;

                                                          method setViewEngine

                                                          setViewEngine: (engine: string) => any;

                                                            method status

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

                                                              method useBodyParser

                                                              useBodyParser: <Options = NestExpressBodyParserOptions>(
                                                              type: NestExpressBodyParserType,
                                                              rawBody: boolean,
                                                              options?: Omit<Options, 'verify'>
                                                              ) => this;

                                                                method useStaticAssets

                                                                useStaticAssets: (path: string, options: ServeStaticOptions) => any;

                                                                  class MulterModule

                                                                  class MulterModule {}

                                                                  method register

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

                                                                    method registerAsync

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

                                                                      Interfaces

                                                                      interface MulterModuleAsyncOptions

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

                                                                      property inject

                                                                      inject?: any[];

                                                                        property useClass

                                                                        useClass?: Type<MulterOptionsFactory>;

                                                                          property useExisting

                                                                          useExisting?: Type<MulterOptionsFactory>;

                                                                            property useFactory

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

                                                                              interface MulterOptionsFactory

                                                                              interface MulterOptionsFactory {}

                                                                              method createMulterOptions

                                                                              createMulterOptions: () => Promise<MulterModuleOptions> | MulterModuleOptions;

                                                                                interface NestExpressApplication

                                                                                interface NestExpressApplication<
                                                                                TServer extends CoreHttpServer | CoreHttpsServer = CoreHttpServer
                                                                                > extends INestApplication<TServer> {}
                                                                                • Interface describing methods on NestExpressApplication.

                                                                                  See Also

                                                                                  • [Platform](https://docs.nestjs.com/first-steps#platform)

                                                                                method disable

                                                                                disable: (...args: any[]) => this;
                                                                                • A wrapper function around native express.disable() method.

                                                                                  Returns

                                                                                  {this}

                                                                                  Example 1

                                                                                  app.disable('x-powered-by')

                                                                                method enable

                                                                                enable: (...args: any[]) => this;
                                                                                • A wrapper function around native express.enable() method.

                                                                                  Returns

                                                                                  {this}

                                                                                  Example 1

                                                                                  app.enable('x-powered-by')

                                                                                method engine

                                                                                engine: (...args: any[]) => this;
                                                                                • A wrapper function around native express.engine() method.

                                                                                  Returns

                                                                                  {this}

                                                                                  Example 1

                                                                                  app.engine('mustache', mustacheExpress())

                                                                                method getHttpAdapter

                                                                                getHttpAdapter: () => HttpServer<Express.Request, Express.Response, Express>;
                                                                                • Returns the underlying HTTP adapter bounded to the Express.js app.

                                                                                  Returns

                                                                                  {HttpServer}

                                                                                method listen

                                                                                listen: {
                                                                                (port: number | string, callback?: () => void): Promise<TServer>;
                                                                                (
                                                                                port: string | number,
                                                                                hostname: string,
                                                                                callback?: () => void
                                                                                ): Promise<TServer>;
                                                                                };
                                                                                • Starts the application.

                                                                                  Parameter port

                                                                                  Parameter hostname

                                                                                  Parameter callback

                                                                                  Optional callback

                                                                                  Returns

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

                                                                                method set

                                                                                set: (...args: any[]) => this;
                                                                                • A wrapper function around native express.set() method.

                                                                                  Returns

                                                                                  {this}

                                                                                  Example 1

                                                                                  app.set('trust proxy', 'loopback')

                                                                                method setBaseViewsDir

                                                                                setBaseViewsDir: (path: string | string[]) => this;
                                                                                • Sets one or multiple base directories for templates (views).

                                                                                  Returns

                                                                                  {this}

                                                                                  Example 1

                                                                                  app.setBaseViewsDir('views')

                                                                                method setLocal

                                                                                setLocal: (key: string, value: any) => this;
                                                                                • Sets app-level globals for view templates.

                                                                                  Returns

                                                                                  {this}

                                                                                  Example 1

                                                                                  app.setLocal('title', 'My Site')

                                                                                  See Also

                                                                                  • https://expressjs.com/en/4x/api.html#app.locals

                                                                                method setViewEngine

                                                                                setViewEngine: (engine: string) => this;
                                                                                • Sets a view engine for templates (views).

                                                                                  Returns

                                                                                  {this}

                                                                                  Example 1

                                                                                  app.setViewEngine('pug')

                                                                                method useBodyParser

                                                                                useBodyParser: <Options = NestExpressBodyParserOptions>(
                                                                                parser: NestExpressBodyParserType,
                                                                                options?: Omit<Options, 'verify'>
                                                                                ) => this;
                                                                                • Register Express body parsers on the fly. Will respect the application's rawBody option.

                                                                                  Returns

                                                                                  {this}

                                                                                  Example 1

                                                                                  const app = await NestFactory.create( AppModule, { rawBody: true } ); app.useBodyParser('json', { limit: '50mb' });

                                                                                method useStaticAssets

                                                                                useStaticAssets: {
                                                                                (options: ServeStaticOptions): this;
                                                                                (path: string, options?: ServeStaticOptions): this;
                                                                                };
                                                                                • Sets a base directory for public assets.

                                                                                  Returns

                                                                                  {this}

                                                                                  Example 1

                                                                                  app.useStaticAssets('public')

                                                                                interface NestExpressBodyParserOptions

                                                                                interface NestExpressBodyParserOptions {}
                                                                                • Type alias to keep compatibility with @types/body-parser

                                                                                  See Also

                                                                                  • https://github.com/DefinitelyTyped/DefinitelyTyped/blob/dcd1673c4fa18a15ea8cd8ff8af7d563bb6dc8e6/types/body-parser/index.d.ts#L48-L66#L48-L66

                                                                                property inflate

                                                                                inflate?: boolean | undefined;
                                                                                • When set to true, then deflated (compressed) bodies will be inflated; when false, deflated bodies are rejected. Defaults to true.

                                                                                property limit

                                                                                limit?: number | string | undefined;
                                                                                • Controls the maximum request body size. If this is a number, then the value specifies the number of bytes; if it is a string, the value is passed to the bytes library for parsing. Defaults to '100kb'.

                                                                                property type

                                                                                type?: string | string[] | ((req: IncomingMessage) => any) | undefined;
                                                                                • The type option is used to determine what media type the middleware will parse

                                                                                index signature

                                                                                [key: string]: unknown;

                                                                                  Type Aliases

                                                                                  type MulterModuleOptions

                                                                                  type MulterModuleOptions = MulterOptions;

                                                                                    type NestExpressBodyParserType

                                                                                    type NestExpressBodyParserType = 'json' | 'urlencoded' | 'text' | 'raw';
                                                                                    • Interface defining possible body parser types, to be used with NestExpressApplication.useBodyParser().

                                                                                    Package Files (12)

                                                                                    Dependencies (5)

                                                                                    Dev Dependencies (2)

                                                                                    Peer Dependencies (2)

                                                                                    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-express.

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