Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Module

app.put

Defines a route that handles HTTP PUT requests for a specified path. Express runs the supplied callback functions when the request method and path match.

How it works

app.put() registers one or more handlers for a specific URL path and matches only incoming HTTP PUT requests for that path. When a request matches, Express runs the callback with the request and response objects, allowing the handler to produce the response.

Syntax

app.put(path, callback [, callback ...])

Parameters

NameTypeDescription
pathstring or path patternThe route path to match, such as /users/:id.
callback functionsfunctionOne or more callback functions invoked for a matching PUT request.

Returns

Registers the PUT route on the application; the documentation does not specify a distinct return value for this method.

Key points

  • It maps a URL path to callback functions for incoming HTTP PUT requests.
  • Express exposes HTTP-method-specific application methods, including app.put().
  • A handler receives req and res, which provide request data and response operations.
  • A PUT handler can finish the request by sending a response with res.send().

Common mistakes

  • The method is tied to the HTTP verb: this route does not handle GET, POST, or other methods.

Example: Handle a PUT route

const express = require('express');
const app = express();

app.put('/users/:id', (req, res) => {
  res.send(`Updated user ${req.params.id}`);
});

app.listen(3000);

Creates a route that responds to PUT requests for a user identified by a path parameter.

When to use it

Resource updates

Update a resource at a URL such as /users/:id.

Middleware pipelines

Attach multiple processing stages before the final response handler.

Method-specific APIs

Handle a PUT endpoint alongside GET, POST, and DELETE routes.

Interview questions

QWhat does app.put() do?

app.put(path, handler) defines a route for HTTP PUT requests at the specified path. Express invokes the handler when both the request method and route path match.

Follow-up: How would you support several methods on one path? Use app.route(path) and chain method-specific handlers such as .get(), .post(), and .put().

QWhat are the main arguments to app.put()?

The first argument identifies the route path, such as /users/:id. The callback receives the request and response objects and can send the result with methods such as res.send().

Follow-up: How do you read the :id value? Access the route parameter through req.params.id inside the handler.

QHow does app.put() relate to other application routing methods?

Express provides explicit application-method entries for common HTTP methods, including app.put(). The method name corresponds to the lowercase HTTP method handled by the route.

Follow-up: How can middleware be applied at application level? Use app.use() or an application method with middleware functions before the final handler.

  • app.get()
  • app.post()
  • app.delete()
  • app.route()
  • app.use()
  • req
  • res

Source: Application Object · Express.js 4.x. Checked 2026-10-15.