Resource creation
Create resources such as users, orders, or comments from submitted request data.
Express.js · Module
app.post() registers one or more handlers for HTTP POST requests matching a specified path. The path supports strings, patterns, regular expressions, or arrays of these forms.
app.post() registers callback functions for HTTP POST requests that match a specified path. The path can be a string, path pattern, regular expression, or array, and the callbacks run as route middleware for matching requests.
app.post(path, [callback...], callback)| Name | Type | Description |
|---|---|---|
path | String | RegExp | Array | Path or path pattern matched by the route; accepts a string, regular expression, or array of combinations. |
callback functions | Function | Function[] | One or more callback functions used as route middleware and the final request handler. |
Routes HTTP POST requests to the specified path with the specified callback functions.
const express = require('express');
const app = express();
app.post('/users', (req, res) => {
res.send('User created');
});
app.listen(3000);Creates a POST route at /users and sends a response when that route receives a matching request.
Create resources such as users, orders, or comments from submitted request data.
Run validation, authorization, and business logic in an ordered handler chain.
Handle form submissions or API commands addressed to a specific endpoint.
app.post() routes HTTP POST requests to a selected path and runs the supplied callback functions for matching requests. The path may be a string, pattern, regular expression, or array.
Follow-up: How can several handlers be composed? Pass multiple callback functions, which behave like middleware, and call next('route') to bypass the remaining callbacks for that route.
The first argument is the route path. It accepts a String, RegExp, or Array containing combinations of supported path forms.
Follow-up: What does an array provide? It lets one route definition match multiple path representations through a single registration.
The callback receives the request and response objects, and can send the response for the POST request. Express invokes it when both the path and HTTP method match.
Follow-up: How would you add preprocessing? Supply additional callback functions before the final handler and pass control between them with next().
app.get()app.put()app.delete()app.route()router.post()