Routing resfers to the definition of application end points (URIs) and how they response to client requests.
- express class -> routing methods -> http methods
- route path based on strings
- route path based on string patterns
- route path based on regular expressions
- response.download()
- response.end()
- response.json()
- response.jsonp()
- response.redirect()
- response.render()
- response.send()
- response.sendFile()
- response.sendStatus()
Use the express.Router class to create modular, mountable route handlers.
Middleware -> request, response, next
Middleware function can perform the following tasks:
- Excute any code.
- Make changes to the request and the response objects.
- End the request-response cycle.
- Call the next middleware in the stack.
Refer to cookie-session and compression for examples of configurable middleware.
An Express web application is essentially a series of middleware function calls.
An Express application can use the following types of middleware.
- Application level middleware
- Router level middleware
- Error handling level middleware
- Building middleware
- Third party middleware
app.use([mounted path], <middleware function handler>)
app.httpMethod([mounted path], <middleware function handler>)
Router level middleware is bound to an instance of express.Router().
A template engine enables you to use static template files in your application.
app.set("views", "the directory of template files")
app.set("view engine", "the name of the view engine")
DEBUG=smaple-app,html,mail,express:* node index.js