Express.js provides several built-in methods and middleware functions that simplify request handling, routing, serving static files, and parsing request bodies. This reference lists the commonly used express() methods along with their purpose.
Express.js express() Methods:
Method | Description |
|---|---|
The express.json() function is a built-in middleware function in Express. It parses incoming requests with JSON payloads and is based on body-parser. | |
The express.raw() function is a built-in middleware function in Express. It parses incoming request payloads into a Buffer and is based on body-parser | |
The express.Router() function is used to create a new router object. This function is used when you want to create a new router object in your program to handle requests. | |
The express.static() function is a built-in middleware function in Express. It serves static files and is based on serve-static. | |
The express.text() function is a built-in middleware function in Express. It parses the incoming request payloads into a string and is based on body-parser. | |
The express.urlencoded() function is a built-in middleware function in Express. It parses incoming requests with URL-encoded payloads and is based on a body parser. |