3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
9 HTTP status utility for node.
11 This module provides a list of status codes and messages sourced from
12 a few different projects:
14 * The [IANA Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml)
15 * The [Node.js project](https://nodejs.org/)
16 * The [NGINX project](https://www.nginx.com/)
17 * The [Apache HTTP Server project](https://httpd.apache.org/)
21 This is a [Node.js](https://nodejs.org/en/) module available through the
22 [npm registry](https://www.npmjs.com/). Installation is done using the
23 [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
26 $ npm install statuses
31 <!-- eslint-disable no-unused-vars -->
34 var status = require('statuses')
37 ### var code = status(Integer || String)
39 If `Integer` or `String` is a valid HTTP code or status message, then the
40 appropriate `code` will be returned. Otherwise, an error will be thrown.
42 <!-- eslint-disable no-undef -->
46 status('403') // => 403
47 status('forbidden') // => 403
48 status('Forbidden') // => 403
49 status(306) // throws, as it's not supported by node.js
52 ### status.STATUS_CODES
54 Returns an object which maps status codes to status messages, in
55 the same format as the
56 [Node.js http module](https://nodejs.org/dist/latest/docs/api/http.html#http_http_status_codes).
60 Returns an array of all the status codes as `Integer`s.
62 ### var msg = status[code]
64 Map of `code` to `status message`. `undefined` for invalid `code`s.
66 <!-- eslint-disable no-undef, no-unused-expressions -->
69 status[404] // => 'Not Found'
72 ### var code = status[msg]
74 Map of `status message` to `code`. `msg` can either be title-cased or
75 lower-cased. `undefined` for invalid `status message`s.
77 <!-- eslint-disable no-undef, no-unused-expressions -->
80 status['not found'] // => 404
81 status['Not Found'] // => 404
84 ### status.redirect[code]
86 Returns `true` if a status code is a valid redirect status.
88 <!-- eslint-disable no-undef, no-unused-expressions -->
91 status.redirect[200] // => undefined
92 status.redirect[301] // => true
95 ### status.empty[code]
97 Returns `true` if a status code expects an empty body.
99 <!-- eslint-disable no-undef, no-unused-expressions -->
102 status.empty[200] // => undefined
103 status.empty[204] // => true
104 status.empty[304] // => true
107 ### status.retry[code]
109 Returns `true` if you should retry the rest.
111 <!-- eslint-disable no-undef, no-unused-expressions -->
114 status.retry[501] // => undefined
115 status.retry[503] // => true
118 [npm-image]: https://img.shields.io/npm/v/statuses.svg
119 [npm-url]: https://npmjs.org/package/statuses
120 [node-version-image]: https://img.shields.io/node/v/statuses.svg
121 [node-version-url]: https://nodejs.org/en/download
122 [travis-image]: https://img.shields.io/travis/jshttp/statuses.svg
123 [travis-url]: https://travis-ci.org/jshttp/statuses
124 [coveralls-image]: https://img.shields.io/coveralls/jshttp/statuses.svg
125 [coveralls-url]: https://coveralls.io/r/jshttp/statuses?branch=master
126 [downloads-image]: https://img.shields.io/npm/dm/statuses.svg
127 [downloads-url]: https://npmjs.org/package/statuses