Options
All
  • Public
  • Public/Protected
  • All
Menu

Class App

Main App class.

Hierarchy

  • App

Index

Constructors

constructor

  • new App(): App

Events

init

  • Init the app module and start the HTTP(S) server.

    Parameters

    • Optional middlewares: MiddlewareDefs

      List of middlewares to be appended / prepended.

    Returns void

kill

  • kill(): void
  • Kill the underlying HTTP(S) server(s).

    Returns void

start

  • start(): Http2Server | Http2SecureServer
  • Start the HTTP(S) server.

    Returns Http2Server | Http2SecureServer

    The HTTP(S) server created by Express.

Properties

events

events: EventEmitter = new EventEmitter()

Event emitter.

expressApp

expressApp: express.Application

Express application.

server

server: any

The underlying HTTP(S) server.

Methods

all

  • all(reqPath: string | RegExp | any[], ...callbacks: any[]): any
  • Shortcut to express ".all()".

    Parameters

    • reqPath: string | RegExp | any[]

      The path for which the middleware function is invoked.

    • Rest ...callbacks: any[]

      Single, array or series of middlewares.

    Returns any

delete

  • delete(reqPath: string | RegExp | any[], ...callbacks: any[]): any
  • Shortcut to express ".delete()".

    Parameters

    • reqPath: string | RegExp | any[]

      The path for which the middleware function is invoked.

    • Rest ...callbacks: any[]

      Single, array or series of middlewares.

    Returns any

get

  • get(reqPath: string | RegExp | any[], ...callbacks: any[]): any
  • Shortcut to express ".get()".

    Parameters

    • reqPath: string | RegExp | any[]

      The path for which the middleware function is invoked.

    • Rest ...callbacks: any[]

      Single, array or series of middlewares.

    Returns any

newInstance

  • newInstance(): App
  • Returns a new fresh instance of the App module.

    Returns App

off

  • off(eventName: string, callback: ListenerFn): void
  • Unbind callback from event. Shortcut to events.off().

    Parameters

    • eventName: string

      The name of the event.

    • callback: ListenerFn

      Callback function.

    Returns void

on

  • on(eventName: string, callback: ListenerFn): void
  • Bind callback to event. Shortcut to events.on().

    Parameters

    • eventName: string

      The name of the event.

    • callback: ListenerFn

      Callback function.

    Returns void

once

  • once(eventName: string, callback: ListenerFn): void
  • Bind callback to event that will be triggered only once. Shortcut to events.once().

    Parameters

    • eventName: string

      The name of the event.

    • callback: ListenerFn

      Callback function.

    Returns void

patch

  • patch(reqPath: string | RegExp | any[], ...callbacks: any[]): any
  • Shortcut to express ".patch()".

    Parameters

    • reqPath: string | RegExp | any[]

      The path for which the middleware function is invoked.

    • Rest ...callbacks: any[]

      Single, array or series of middlewares.

    Returns any

post

  • post(reqPath: string | RegExp | any[], ...callbacks: any[]): any
  • Shortcut to express ".post()".

    Parameters

    • reqPath: string | RegExp | any[]

      The path for which the middleware function is invoked.

    • Rest ...callbacks: any[]

      Single, array or series of middlewares.

    Returns any

put

  • put(reqPath: string | RegExp | any[], ...callbacks: any[]): any
  • Shortcut to express ".put()".

    Parameters

    • reqPath: string | RegExp | any[]

      The path for which the middleware function is invoked.

    • Rest ...callbacks: any[]

      Single, array or series of middlewares.

    Returns any

renderError

  • renderError(req: express.Request, res: express.Response, error: any, status?: number | string): void
  • Sends error response as JSON.

    Parameters

    • req: express.Request

      The Express request object.

    • res: express.Response

      The Express response object.

    • error: any

      The error object or message to be sent to the client.

    • Optional status: number | string

      The response status code, optional, default is 500.

    Returns void

renderImage

  • renderImage(req: express.Request, res: express.Response, filename: string, options?: any): void
  • Render an image from the speficied file, and send to the client.

    Parameters

    • req: express.Request

      The Express request object.

    • res: express.Response

      The Express response object.

    • filename: string

      The full path to the image file.

    • Optional options: any

      Options passed to the image renderer, for example the "mimetype".

    Returns void

renderJson

  • renderJson(req: express.Request, res: express.Response, data: any, status?: number): void
  • Render response as JSON data and send to the client.

    Parameters

    • req: express.Request

      The Express request object.

    • res: express.Response

      The Express response object.

    • data: any

      The JSON data to be sent.

    • Optional status: number

      Optional status code, defaults to 200.

    Returns void

renderText

  • renderText(req: express.Request, res: express.Response, text: any, status?: number): void
  • Sends pure text to the client.

    Parameters

    • req: express.Request

      The Express request object.

    • res: express.Response

      The Express response object.

    • text: any

      The text to be rendered, mandatory.

    • Optional status: number

      Optional status code, defaults to 200.

    Returns void

renderView

  • renderView(req: express.Request, res: express.Response, view: string, options?: any, status?: number): void
  • Render a view and send to the client. The view engine depends on the settings defined.

    Parameters

    • req: express.Request

      The Express request object.

    • res: express.Response

      The Express response object.

    • view: string

      The view filename.

    • Optional options: any

      Options passed to the view, optional.

    • Optional status: number

      Optional status code, defaults to 200.

    Returns void

route

  • route(reqPath: string): express.IRoute
  • Shortcut to express ".route()".

    Parameters

    • reqPath: string

      The path of the desired route.

    Returns express.IRoute

    An instance of a single route for the specified path.

use

  • use(reqPath?: string, ...callbacks: any[]): any
  • Shortcut to express ".use()".

    Parameters

    • Optional reqPath: string

      The path for which the middleware function is invoked.

    • Rest ...callbacks: any[]

      Single, array or series of middlewares.

    Returns any

Generated using TypeDoc