@nestjs/platform-express
- Version 12.0.1
- Published
- 62.6 kB
- 5 dependencies
- MIT license
Install
npm i @nestjs/platform-expressyarn add @nestjs/platform-expresspnpm add @nestjs/platform-expressOverview
Nest - modern, fast, powerful node.js web framework (@platform-express)
Index
Functions
Classes
ExpressAdapter
- appendHeader()
- applyVersionFilter()
- beforeClose()
- close()
- createMiddlewareFactory()
- disable()
- enable()
- enableCors()
- end()
- engine()
- getHeader()
- getRequestHostname()
- getRequestMethod()
- getRequestUrl()
- getType()
- initHttpServer()
- isHeadersSent()
- isRouteOrderSensitive()
- listen()
- mapException()
- normalizePath()
- redirect()
- registerParserMiddleware()
- render()
- reply()
- set()
- setBaseViewsDir()
- setErrorHandler()
- setHeader()
- setLocal()
- setNotFoundHandler()
- setOnRequestHook()
- setOnResponseHook()
- setViewEngine()
- status()
- useBodyParser()
- useStaticAssets()
Interfaces
Type Aliases
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 beforeClose
beforeClose: () => void;method close
close: () => Promise<unknown> | undefined;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 isRouteOrderSensitive
isRouteOrderSensitive: () => boolean;method listen
listen: { (port: string | number, callback?: () => void): Server; (port: string | number, hostname: string, callback?: () => void): Server;};method mapException
mapException: (error: unknown) => unknown;method normalizePath
normalizePath: (path: string) => string;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 setOnRequestHook
setOnRequestHook: ( onRequestHook: ( req: express.Request, res: express.Response, done: () => void ) => Promise<void> | void) => void;method setOnResponseHook
setOnResponseHook: ( onResponseHook: ( req: express.Request, res: express.Response ) => Promise<void> | void) => void;method setViewEngine
setViewEngine: (engine: string) => any;method status
status: (response: any, statusCode: number) => any;method useBodyParser
useBodyParser: <ParserType extends keyof NestExpressBodyParserOptionsMap>( type: ParserType, rawBody: boolean, options?: NestExpressBodyParserOptionsFor<ParserType>) => 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 enableCors
enableCors: (options?: CorsOptions | CorsOptionsDelegate<any>) => void;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: <ParserType extends keyof NestExpressBodyParserOptionsMap>( parser: ParserType, options?: NestExpressBodyParserOptionsFor<ParserType>) => this;Register Express body parsers on the fly. Will respect the application's
rawBodyoption.Returns
{this}
Example 1
const app = await NestFactory.create( AppModule, { rawBody: true } ); app.useBodyParser('json', { limit: '50mb' });
The accepted options are narrowed by the
parserargument, souseBodyParser('json', ...)only acceptsexpress.jsonoptions,useBodyParser('urlencoded', ...)only acceptsexpress.urlencodedoptions, and so on.
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
Deprecated
Prefer NestExpressBodyParserOptionsFor, which resolves the exact options type for a given parser. The catch-all index signature below makes
keyofresolve tostring | number, which disables excess-property checking and makesOmit<_, 'verify'>a no-op.
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;interface NestExpressBodyParserOptionsMap
interface NestExpressBodyParserOptionsMap {}Maps each body parser to the options object accepted by its Express factory.
Derived from
expressitself so the two can never drift:useBodyParserultimately callsexpress[parser](options).
property json
json: NonNullable<Parameters<Express['json']>[0]>;property raw
raw: NonNullable<Parameters<Express['raw']>[0]>;property text
text: NonNullable<Parameters<Express['text']>[0]>;property urlencoded
urlencoded: NonNullable<Parameters<Express['urlencoded']>[0]>;Type Aliases
type MulterModuleOptions
type MulterModuleOptions = MulterOptions;type NestExpressBodyParserOptionsFor
type NestExpressBodyParserOptionsFor<ParserType extends NestExpressBodyParserType> = Omit<NestExpressBodyParserOptionsMap[ParserType], 'verify'>;Options accepted by a given body parser.
verifyis excluded because it is reserved: Nest sets it internally to capture the raw request body when the application is created with{ rawBody: true }.
type NestExpressBodyParserType
type NestExpressBodyParserType = keyof NestExpressBodyParserOptionsMap;Interface defining possible body parser types, to be used with
NestExpressApplication.useBodyParser().
Package Files (12)
- adapters/express-adapter.d.ts
- index.d.ts
- interfaces/nest-express-application.interface.d.ts
- interfaces/nest-express-body-parser-options.interface.d.ts
- interfaces/nest-express-body-parser.interface.d.ts
- multer/interceptors/any-files.interceptor.d.ts
- multer/interceptors/file-fields.interceptor.d.ts
- multer/interceptors/file.interceptor.d.ts
- multer/interceptors/files.interceptor.d.ts
- multer/interceptors/no-files.interceptor.d.ts
- multer/interfaces/files-upload-module.interface.d.ts
- multer/multer.module.d.ts
Dependencies (5)
Dev Dependencies (2)
Peer Dependencies (2)
Badge
To add a badge like this oneto 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[](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>
- Updated .
Package analyzed in 4102 ms. - Missing or incorrect documentation? Open an issue for this package.
