Skip to Content
Learning TypeScript 2.x - Second Edition
book

Learning TypeScript 2.x - Second Edition

by Remo H. Jansen
April 2018
Beginner content levelBeginner
536 pages
13h 21m
English
Packt Publishing
Content preview from Learning TypeScript 2.x - Second Edition

Express middleware

Express also allows us to declare a middleware function. A middleware function allows us to implement cross-cutting concerns. A cross-cutting concern is a requirement that affects the entire application or a subset of it. Common examples of cross-cutting concerns are logging and authorization.

A middleware function takes the current request and response as arguments together with a function known as next:

const middlewareFunction = ( 
    req: express.Request, 
    res: express.Response, 
    next: express.NextFunction 
) => { 
    next(); 
}; 

We can chain middleware functions, and the next function is what communicates to Express that the middleware has finished its task and the next middleware can be invoked. When no more middleware functions ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering TypeScript - Fourth Edition

Mastering TypeScript - Fourth Edition

Nathan Rozentals
Learning TypeScript

Learning TypeScript

Josh Goldberg
TypeScript for Beginners

TypeScript for Beginners

Bharath Thippireddy

Publisher Resources

ISBN: 9781788391474Supplemental Content