What is methods?
The 'methods' npm package provides a list of HTTP methods that are supported by the Node.js core, which can be useful for handling and parsing HTTP requests in web applications. It is often used in conjunction with other packages like Express to ensure consistency in method names and provide utility functions for working with HTTP methods.
What are methods's main functionalities?
List of HTTP methods
This feature provides an array of lower-cased HTTP method names that are supported by the Node.js core. It can be used to iterate over or validate HTTP methods in web applications.
const methods = require('methods');
console.log(methods); // outputs an array of HTTP methods
Other packages similar to methods
http
The 'http' module is a built-in Node.js module that provides utilities for server creation and handling HTTP requests. It does not provide a list of methods like 'methods' does, but it is the core package for handling HTTP in Node.js.
express
Express is a popular web framework for Node.js that uses the 'methods' package internally to handle routing based on HTTP methods. It provides a more feature-rich API for building web applications, including middleware support, routing, and more.
koa
Koa is another web framework for Node.js that is similar to Express but with a different design philosophy, focusing on a smaller core and using async functions. It does not use the 'methods' package directly but has its own way of handling HTTP methods.
Methods
HTTP verbs that Node.js core's HTTP parser supports.
This module provides an export that is just like http.METHODS
from Node.js core,
with the following differences:
- All method names are lower-cased.
- Contains a fallback list of methods for Node.js versions that do not have a
http.METHODS
export (0.10 and lower). - Provides the fallback list when using tools like
browserify
without pulling
in the http
shim module.
Install
$ npm install methods
API
var methods = require('methods')
methods
This is an array of lower-cased method names that Node.js supports. If Node.js
provides the http.METHODS
export, then this is the same array lower-cased,
otherwise it is a snapshot of the verbs from Node.js 0.10.
License
MIT