Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • Locals: Record<string, any> = Record<string, any>

Hierarchy

Callable

  • Express instance itself is a request handler, which could be invoked without third argument.

    Parameters

    Returns any

  • Parameters

    Returns void

Index

Properties

_router: any

Used to get all registered routes in Express Application

all: IRouterMatcher<Application<Locals>, "all">

Special-cased "all" method, applying the given route path, middleware, and callback to every HTTP method.

checkout: IRouterMatcher<Application<Locals>, any>
connect: IRouterMatcher<Application<Locals>, any>
copy: IRouterMatcher<Application<Locals>, any>
delete: IRouterMatcher<Application<Locals>, "delete">
get: ((name: string) => any) & IRouterMatcher<Application<Locals>, any>
head: IRouterMatcher<Application<Locals>, "head">
locals: Locals
lock: IRouterMatcher<Application<Locals>, any>
m-search: IRouterMatcher<Application<Locals>, any>
map: any
merge: IRouterMatcher<Application<Locals>, any>
mkactivity: IRouterMatcher<Application<Locals>, any>
mkcol: IRouterMatcher<Application<Locals>, any>
mountpath: string | string[]

The app.mountpath property contains one or more path patterns on which a sub-app was mounted.

move: IRouterMatcher<Application<Locals>, any>
notify: IRouterMatcher<Application<Locals>, any>
options: IRouterMatcher<Application<Locals>, "options">
patch: IRouterMatcher<Application<Locals>, "patch">
post: IRouterMatcher<Application<Locals>, "post">
propfind: IRouterMatcher<Application<Locals>, any>
proppatch: IRouterMatcher<Application<Locals>, any>
purge: IRouterMatcher<Application<Locals>, any>
put: IRouterMatcher<Application<Locals>, "put">
report: IRouterMatcher<Application<Locals>, any>
resource: any
router: string
routes: any

The app.routes object houses all of the routes defined mapped by the associated HTTP verb. This object may be used for introspection capabilities, for example Express uses this internally not only for routing but to provide default OPTIONS behaviour unless app.options() is used. Your application or framework may also remove routes by simply by removing them from this object.

search: IRouterMatcher<Application<Locals>, any>
settings: any
stack: any[]

Stack of configured routes

subscribe: IRouterMatcher<Application<Locals>, any>
trace: IRouterMatcher<Application<Locals>, any>
unlock: IRouterMatcher<Application<Locals>, any>
unsubscribe: IRouterMatcher<Application<Locals>, any>

Methods

  • defaultConfiguration(): void
  • Initialize application configuration.

    Returns void

  • Disable setting.

    Parameters

    • setting: string

    Returns Application<Locals>

  • disabled(setting: string): boolean
  • Check if setting is disabled.

    app.disabled('foo') // => true

    app.enable('foo') app.disabled('foo') // => false

    Parameters

    • setting: string

    Returns boolean

  • Enable setting.

    Parameters

    • setting: string

    Returns Application<Locals>

  • enabled(setting: string): boolean
  • Check if setting is enabled (truthy).

    app.enabled('foo') // => false

    app.enable('foo') app.enabled('foo') // => true

    Parameters

    • setting: string

    Returns boolean

  • engine(ext: string, fn: (path: string, options: object, callback: (e: any, rendered?: string) => void) => void): Application<Locals>
  • Register the given template engine callback fn as ext.

    By default will require() the engine based on the file extension. For example if you try to render a "foo.jade" file Express will invoke the following internally:

    app.engine('jade', require('jade').__express);
    

    For engines that do not provide .__express out of the box, or if you wish to "map" a different extension to the template engine you may use this method. For example mapping the EJS template engine to ".html" files:

    app.engine('html', require('ejs').renderFile);
    

    In this case EJS provides a .renderFile() method with the same signature that Express expects: (path, options, callback), though note that it aliases this method as ejs.__express internally so if you're using ".ejs" extensions you dont need to do anything.

    Some template engines do not follow this convention, the Consolidate.js library was created to map all of node's popular template engines to follow this convention, thus allowing them to work seamlessly within Express.

    Parameters

    • ext: string
    • fn: (path: string, options: object, callback: (e: any, rendered?: string) => void) => void
        • (path: string, options: object, callback: (e: any, rendered?: string) => void): void
        • Parameters

          • path: string
          • options: object
          • callback: (e: any, rendered?: string) => void
              • (e: any, rendered?: string): void
              • Parameters

                • e: any
                • Optional rendered: string

                Returns void

          Returns void

    Returns Application<Locals>

  • init(): void
  • Initialize the server.

    • setup default configuration
    • setup default middleware
    • setup route reflection methods

    Returns void

  • listen(port: number, hostname: string, backlog: number, callback?: () => void): Server<typeof IncomingMessage, typeof ServerResponse>
  • listen(port: number, hostname: string, callback?: () => void): Server<typeof IncomingMessage, typeof ServerResponse>
  • listen(port: number, callback?: () => void): Server<typeof IncomingMessage, typeof ServerResponse>
  • listen(callback?: () => void): Server<typeof IncomingMessage, typeof ServerResponse>
  • listen(path: string, callback?: () => void): Server<typeof IncomingMessage, typeof ServerResponse>
  • listen(handle: any, listeningListener?: () => void): Server<typeof IncomingMessage, typeof ServerResponse>
  • Listen for connections.

    A node http.Server is returned, with this application (which is a Function) as its callback. If you wish to create both an HTTP and HTTPS server you may do so with the "http" and "https" modules as shown here:

    var http = require('http') , https = require('https') , express = require('express') , app = express();

    http.createServer(app).listen(80); https.createServer({ ... }, app).listen(443);

    Parameters

    • port: number
    • hostname: string
    • backlog: number
    • Optional callback: () => void
        • (): void
        • Returns void

    Returns Server<typeof IncomingMessage, typeof ServerResponse>

  • Parameters

    • port: number
    • hostname: string
    • Optional callback: () => void
        • (): void
        • Returns void

    Returns Server<typeof IncomingMessage, typeof ServerResponse>

  • Parameters

    • port: number
    • Optional callback: () => void
        • (): void
        • Returns void

    Returns Server<typeof IncomingMessage, typeof ServerResponse>

  • Parameters

    • Optional callback: () => void
        • (): void
        • Returns void

    Returns Server<typeof IncomingMessage, typeof ServerResponse>

  • Parameters

    • path: string
    • Optional callback: () => void
        • (): void
        • Returns void

    Returns Server<typeof IncomingMessage, typeof ServerResponse>

  • Parameters

    • handle: any
    • Optional listeningListener: () => void
        • (): void
        • Returns void

    Returns Server<typeof IncomingMessage, typeof ServerResponse>

  • on(event: string, callback: (parent: Application<Record<string, any>>) => void): this
  • The mount event is fired on a sub-app, when it is mounted on a parent app. The parent app is passed to the callback function.

    NOTE: Sub-apps will:

    • Not inherit the value of settings that have a default value. You must set the value in the sub-app.
    • Inherit the value of settings with no default value.

    Parameters

    • event: string
    • callback: (parent: Application<Record<string, any>>) => void
        • Parameters

          Returns void

    Returns this

  • Map the given param placeholder name(s) to the given callback(s).

    Parameter mapping is used to provide pre-conditions to routes which use normalized placeholders. For example a :user_id parameter could automatically load a user's information from the database without any additional code,

    The callback uses the samesignature as middleware, the only differencing being that the value of the placeholder is passed, in this case the id of the user. Once the next() function is invoked, just like middleware it will continue on to execute the route, or subsequent parameter functions.

     app.param('user_id', function(req, res, next, id){
    User.find(id, function(err, user){
    if (err) {
    next(err);
    } else if (user) {
    req.user = user;
    next();
    } else {
    next(new Error('failed to load user'));
    }
    });
    });

    Parameters

    Returns Application<Locals>

  • Alternatively, you can pass only a callback, in which case you have the opportunity to alter the app.param()

    deprecated

    since version 4.11

    Parameters

    Returns Application<Locals>

  • path(): string
  • Return the app's absolute pathname based on the parent(s) that have mounted it.

    For example if the application was mounted as "/admin", which itself was mounted as "/blog" then the return value would be "/blog/admin".

    Returns string

  • render(name: string, options?: object, callback?: (err: Error, html: string) => void): void
  • render(name: string, callback: (err: Error, html: string) => void): void
  • Render the given view name name with options and a callback accepting an error and the rendered template string.

    Example:

    app.render('email', { name: 'Tobi' }, function(err, html){ // ... })

    Parameters

    • name: string
    • Optional options: object
    • Optional callback: (err: Error, html: string) => void
        • (err: Error, html: string): void
        • Parameters

          • err: Error
          • html: string

          Returns void

    Returns void

  • Parameters

    • name: string
    • callback: (err: Error, html: string) => void
        • (err: Error, html: string): void
        • Parameters

          • err: Error
          • html: string

          Returns void

    Returns void

  • Type parameters

    • T: string

    Parameters

    • prefix: T

    Returns IRoute<T>

  • Parameters

    Returns IRoute<string>

  • Assign setting to val, or return setting's value.

    app.set('foo', 'bar'); app.get('foo'); // => "bar" app.set('foo', ['bar', 'baz']); app.get('foo'); // => ["bar", "baz"]

    Mounted servers inherit their parent server's settings.

    Parameters

    • setting: string
    • val: any

    Returns Application<Locals>