Registry / http-networking / methods

methods

JSON →
library1.1.2jsnpmunverified

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.

npm install methods
INSTALL
IMPORT
SIG · METHODS
M
methods
http-networkingjavascriptv1.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

methods
const methods = require('methods')
The package exports a single array by default, primarily designed for CommonJS environments.
methods
import methods from 'methods'
import { methods } from 'methods'
While CommonJS, bundlers often allow default ESM import. Using named imports like `{ methods }` will result in an error as it's not a named export.
METHODS_ARRAY
const METHODS_ARRAY = require('methods')
The exported value is an array of strings, so it's often assigned to a descriptive constant name.

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'));
Debug
Known issues
gotchaThis package is a CommonJS module and does not officially support native ES Modules (ESM) without a transpiler or bundler. Attempting to use `import { methods } from 'methods'` in a pure ESM environment will fail.
fix
Use `const methods = require('methods')` in CommonJS contexts. For ESM, use `import methods from 'methods'` and rely on bundler configurations, or consider dynamic import: `const { default: methods } = await import('methods')`.
affects: >=1.0.0
gotchaThe package exports a plain JavaScript array of lower-cased HTTP method strings. It is not an object with named properties, nor is it a function. Attempting to call `methods()` or access `methods.GET` will result in errors.
fix
Access the methods directly from the array (e.g., `methods.includes('get')`) or iterate over the array (`methods.forEach(...)`).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: methods is not a function
The imported 'methods' variable is an array, not a function, and was incorrectly invoked as one.
fix
Remove the function call parentheses: `const allMethods = methods;`
SyntaxError: Named export 'methods' not found (module 'methods' does not have an export named 'methods')
Attempting to use named import syntax (`import { methods } from 'methods'`) for a package that provides only a default export (an array in this case) in a CommonJS context or without proper ESM interoperability configuration.
fix
Use a default import for ESM: `import methods from 'methods'`, or the CommonJS `require`: `const methods = require('methods')`.
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
methods — npm install methods · libregistry