{"id":11303,"library":"methods","title":"HTTP Methods List","description":"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.","status":"maintenance","version":"1.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/jshttp/methods","tags":["javascript","http","methods"],"install":[{"cmd":"npm install methods","lang":"bash","label":"npm"},{"cmd":"yarn add methods","lang":"bash","label":"yarn"},{"cmd":"pnpm add methods","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a single array by default, primarily designed for CommonJS environments.","symbol":"methods","correct":"const methods = require('methods')"},{"note":"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.","wrong":"import { methods } from 'methods'","symbol":"methods","correct":"import methods from 'methods'"},{"note":"The exported value is an array of strings, so it's often assigned to a descriptive constant name.","symbol":"METHODS_ARRAY","correct":"const METHODS_ARRAY = require('methods')"}],"quickstart":{"code":"const methods = require('methods');\n\nconsole.log('Supported HTTP methods (lower-cased):');\nmethods.forEach(method => {\n  console.log(`- ${method.toUpperCase()}`);\n});\n\n// Example: Check if a method is supported\nconst isSupported = (method) => methods.includes(method.toLowerCase());\nconsole.log('\\nIs GET supported?', isSupported('GET'));\nconsole.log('Is TRACE supported?', isSupported('TRACE'));\nconsole.log('Is INVALID supported?', isSupported('INVALID'));","lang":"javascript","description":"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."},"warnings":[{"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')`.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Access the methods directly from the array (e.g., `methods.includes('get')`) or iterate over the array (`methods.forEach(...)`).","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Remove the function call parentheses: `const allMethods = methods;`","cause":"The imported 'methods' variable is an array, not a function, and was incorrectly invoked as one.","error":"TypeError: methods is not a function"},{"fix":"Use a default import for ESM: `import methods from 'methods'`, or the CommonJS `require`: `const methods = require('methods')`.","cause":"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.","error":"SyntaxError: Named export 'methods' not found (module 'methods' does not have an export named 'methods')"}],"ecosystem":"npm"}