HTTP Methods List

1.1.2 · maintenance · verified Sun Apr 19

The `methods` package, currently at version 1.1.2, provides a normalized, lower-cased array of HTTP method names supported by the Node.js runtime. This module serves as a robust alternative or enhancement to Node.js core's `http.METHODS`, especially for environments requiring broader compatibility. Its key differentiators include automatically lower-casing all method names for consistent usage and offering a fallback list for older Node.js versions (0.10 and below) that predate the `http.METHODS` export. Furthermore, it's designed to function seamlessly with browser bundling tools like Browserify without inadvertently pulling in the larger `http` shim module, making it lightweight for client-side use cases where a list of standard HTTP verbs is needed. The package is very stable, with infrequent updates, reflecting its foundational role and mature status within the Node.js ecosystem, particularly as a utility for web frameworks like Express.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import the `methods` array and iterate through the supported HTTP verbs. It also shows a simple function to check if a specific HTTP method is included in the list.

const methods = require('methods');

console.log('Supported HTTP methods (lower-cased):');
methods.forEach(method => {
  console.log(`- ${method.toUpperCase()}`);
});

// Example: Check if a method is supported
const isSupported = (method) => methods.includes(method.toLowerCase());
console.log('\nIs GET supported?', isSupported('GET'));
console.log('Is TRACE supported?', isSupported('TRACE'));
console.log('Is INVALID supported?', isSupported('INVALID'));

view raw JSON →