or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-methods

HTTP methods that Node.js supports, provided as an array of lowercase method names

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/methods@1.1.x

To install, run

npx @tessl/cli install tessl/npm-methods@1.1.0

index.mddocs/

Methods

Methods is a utility library that provides an array of lowercase HTTP method names supported by Node.js. It serves as a cross-platform compatibility layer by using Node.js core's http.METHODS when available, or falling back to a predefined list for older Node.js versions and browser environments.

Package Information

  • Package Name: methods
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install methods

Core Imports

var methods = require('methods');

ES Modules (via transpilation/bundling):

import methods from 'methods';

Basic Usage

var methods = require('methods');

// methods is an array of lowercase HTTP method names
console.log(methods);
// ['get', 'post', 'put', 'head', 'delete', 'options', 'trace', ...]

// Check if a method is supported
var isSupported = methods.indexOf('get') !== -1;

// Use in HTTP routing
function isValidMethod(method) {
  return methods.indexOf(method.toLowerCase()) !== -1;
}

// Use for validation in web frameworks
if (methods.indexOf(req.method.toLowerCase()) === -1) {
  throw new Error('Unsupported HTTP method');
}

Architecture

Methods has a simple, minimalist architecture designed for maximum compatibility:

  • Runtime Detection: Uses feature detection to check for http.METHODS availability
  • Fallback Strategy: Provides a curated list of 27 HTTP methods for older Node.js versions and browsers
  • Static Export: Returns a pre-computed array that remains constant throughout application lifecycle
  • Zero Dependencies: Self-contained with no external dependencies, reducing bundle size and security surface

The module exports a single array that is determined at load time based on the JavaScript environment.

Capabilities

HTTP Methods Array

The main and only export of the methods package - an array of lowercase HTTP method names.

/**
 * Array of lowercase HTTP method names supported by Node.js
 * @type {string[]}
 */
var methods = require('methods');

Runtime Behavior:

  • Node.js 0.11+: Returns http.METHODS.map(method => method.toLowerCase())
  • Node.js 0.10 and below: Returns predefined array of 27 HTTP methods
  • Browser environments: Returns predefined array (http module not available)

Supported HTTP Methods:

The array contains all standard and extended HTTP methods in lowercase:

  • Standard methods: get, post, put, head, delete, options, trace, patch, connect
  • WebDAV methods: copy, lock, mkcol, move, propfind, proppatch, unlock, mkactivity, checkout, merge
  • Other methods: purge, report, m-search, notify, subscribe, unsubscribe, search

Properties:

  • Type: Array of strings
  • Mutability: Should be treated as read-only
  • Length: Varies by Node.js version (27 methods in fallback, more in newer Node.js versions)
  • Content: All method names are lowercase
  • Ordering: Consistent within same Node.js version

Usage Examples:

var methods = require('methods');

// Iterate through all methods
methods.forEach(function(method) {
  console.log('Supported method:', method);
});

// Check if specific method exists
function hasMethod(methodName) {
  return methods.indexOf(methodName.toLowerCase()) !== -1;
}

// Filter custom methods
var standardMethods = methods.filter(function(method) {
  return ['get', 'post', 'put', 'delete'].indexOf(method) !== -1;
});

// Use in express-like routing
function createHandler(method, path, handler) {
  if (!hasMethod(method)) {
    throw new Error('Invalid HTTP method: ' + method);
  }
  // ... routing logic
}

Types

/**
 * The methods export type definition
 * @typedef {string[]} Methods
 * @description Array of lowercase HTTP method name strings
 */

Error Handling

The methods package does not throw any exceptions during normal operation. It provides a static array that is determined at module load time and remains constant throughout the application lifecycle. The package will only fail if:

  • Node.js itself fails to load the http module (extremely rare)
  • The module file is corrupted or inaccessible

No runtime validation or error checking is performed on the exported array.

Browser Compatibility

The package works in browser environments via browserify or similar bundlers:

// Works in browsers - http module is shimmed out
var methods = require('methods');
// Returns the predefined fallback list

Version Information

  • Current Version: 1.1.2
  • Node.js Support: >= 0.6
  • License: MIT
  • Repository: jshttp/methods

Related Packages

This package is commonly used as a dependency in:

  • HTTP frameworks (Express, Koa, etc.)
  • Routing libraries
  • HTTP clients and servers
  • Method validation utilities
  • Web development tools