• Stars
    star
    433
  • Rank 97,303 (Top 2 %)
  • Language
    CoffeeScript
  • License
    Other
  • Created about 13 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Utility to interact with HTTP status code in Node.js

Build Status

HTTP Status codes for Node

Utility to interact with HTTP status codes.

Usage

Once you require this module, you may call it with either an HTTP code or a message name. With an HTTP code, you will get the message name while with a message name you will get an HTTP code.

HTTP Status Codes

HTTP code names, messages, and classes are respectively accessible with the property {code}_NAME, {code}_MESSAGE and {code}_CLASS. This includes all statuses in the IANA HTTP Status Code Registry, with the only addition being 418 I'm a teapot.

Extra status code are also made available that are not defined in the IANA registry, but used by popular software. They are grouped by category. Specific properties are exported by http-status under the property extra followed by the category name. Also, extra codes are merge with regular status codes and made available as modules available inside http-status/lib/{category}.

Available categories are:

unofficial
This represent a list of codes which are not specified by any standard.
iis
Microsoft's Internet Information Services (IIS) web server expands the 4xx error class to signal errors with the client's request.
nginx
The NGINX web server software expands the 4xx error class to signal issues with the client's request.
cloudflare
Cloudflare's reverse proxy service expands the 5xx error class to signal issues with the origin server.

HTTP Status Code Classes

In addition to HTTP status codes, this module also contains status code classes under the classes property. Similar to HTTP codes, you can access class names and messages with the property {class}_NAME and {class}_MESSAGE

API

The API is structured as follows:

100
100_NAME
100_MESSAGE
100_CLASS
CONTINUE
101
101_NAME
101_MESSAGE
101_CLASS
SWITCHING_PROTOCOLS
…
classes.
β”œβ”€β”€ 1xx
β”œβ”€β”€ 1xx_NAME
β”œβ”€β”€ 1xx_MESSAGE
β”œβ”€β”€ INFORMATIONAL
β”œβ”€β”€ 2xx
β”œβ”€β”€ 2xx_NAME
β”œβ”€β”€ 2xx_MESSAGE
β”œβ”€β”€ SUCCESSFUL
β”œβ”€β”€ …
extra.
β”œβ”€β”€ unofficial.
β”‚   β”œβ”€β”€ 103
β”‚   β”œβ”€β”€ 103_NAME
β”‚   β”œβ”€β”€ 103_MESSAGE
β”‚   β”œβ”€β”€ 103_CLASS
β”‚   β”œβ”€β”€ CHECKPOINT
β”‚   β”œβ”€β”€ …
β”œβ”€β”€ iis.
β”‚   β”œβ”€β”€ 440
β”‚   β”œβ”€β”€ 440_NAME
β”‚   β”œβ”€β”€ 440_MESSAGE
β”‚   β”œβ”€β”€ 440_CLASS
β”‚   β”œβ”€β”€ LOGIN_TIME_OUT
β”‚   β”œβ”€β”€ …
β”œβ”€β”€ nginx.
β”‚   β”œβ”€β”€ 444
β”‚   β”œβ”€β”€ 444_NAME
β”‚   β”œβ”€β”€ 444_MESSAGE
β”‚   β”œβ”€β”€ 444_CLASS
β”‚   β”œβ”€β”€ NO_RESPONSE
β”‚   β”œβ”€β”€ …
β”œβ”€β”€ cloudflare.
β”‚   β”œβ”€β”€ 520
β”‚   β”œβ”€β”€ 520_NAME
β”‚   β”œβ”€β”€ 520_MESSAGE
β”‚   β”œβ”€β”€ 520_CLASS
β”‚   β”œβ”€β”€ UNKNOWN_ERROR
β”‚   β”œβ”€β”€ …

For additional information, please refer to original code.

Example Usage

const status = require('http-status');

console.info(status.INTERNAL_SERVER_ERROR);
// Output: 500

console.info(status[500]);
console.info(status[status.INTERNAL_SERVER_ERROR]);
// Both output: "Internal Server Error"

console.info(status['500_NAME']);
console.info(status[`${status.INTERNAL_SERVER_ERROR}_NAME`]);
// Both output: "INTERNAL_SERVER_ERROR"

console.info(status['500_MESSAGE']);
console.info(status[`${status.INTERNAL_SERVER_ERROR}_MESSAGE`]);
// Both output: "A generic error message, given when an unexpected condition was encountered and no more specific message is suitable."

console.info(status['500_CLASS']);
console.info(status[`${status.INTERNAL_SERVER_ERROR}_CLASS`]);
// Both output: "5xx"

Example using classes

const status = require('http-status');

const responseCode = status.INTERNAL_SERVER_ERROR;

switch (status[`${responseCode}_CLASS`]) {
  case status.classes.INFORMATIONAL:
    // The responseCode is 1xx
    break;
  case status.classes.SUCCESSFUL:
    // The responseCode is 2xx
    break;
  case status.classes.REDIRECTION:
    // The responseCode is 3xx
    break;
  case status.classes.CLIENT_ERROR:
    // The responseCode is 4xx
    break;
  case status.classes.SERVER_ERROR:
    // The responseCode is 5xx
    break;

  default:
    // Unknown
    break;
}

Example Using extra Property

// Accessing property from the NGINX category
const status = require('http-status');
console.info(status.extra.nginx.NO_RESPONSE)
// Accessing default HTTP status merged with NGINX status
const status = require('http-status/lib/nginx');
console.info(status.IM_A_TEAPOT);
console.info(status.NO_RESPONSE)

Express Example

const express = require('express'),
      redis   = require('redis'),
      status  = require('http-status');
// New Express HTTP server
const app = express.createServer();
// Regster a route
app.get('/', (req, res) => {
  const client = redis.createClient();
  client.ping((err, msg) => {
    if (err) {
      return res.send(status.INTERNAL_SERVER_ERROR);
    }
    res.send(msg, status.OK);
  });
});
// Start the HTTP server
app.listen(3000);

Contributors

This package is developed by Adaltas.

Developers

To automatically generate a new version:

rm package-lock.json
yarn run release
git push --follow-tags origin master

Package publication is handled by the CI/CD with GitHub action.

Note:

  • On release, both the publish and test workflows run in parallel. Not very happy about it but I haven't found a better way.
  • yarn does not call the "postrelease" script and npm fails if the package-lock.json file is present and git ignored.

More Repositories

1

node-csv

Full featured CSV parser with simple api and tested against large datasets.
CoffeeScript
3,804
star
2

node-csv-parse

CSV parsing implementing the Node.js `stream.Transform` API
809
star
3

node-hbase

Asynchronous HBase client for NodeJs using REST
CoffeeScript
242
star
4

node-csv-stringify

CSV stringifier implementing the Node.js `stream.Transform` API
187
star
5

node-parameters

Nice looking shell applications with pluggable middlewares for Node.js
CoffeeScript
173
star
6

node-printf

Write formatted data (complete implementation of printf and sprintf) in Node.js
JavaScript
90
star
7

node-csv-generate

CSV and object generation implementing the Node.js `stream.Readable` API
71
star
8

ece-devops-2022-fall

Resources for the ECE 2022 DevOps course
JavaScript
66
star
9

node-nikita

Automation and deployment solution with Node.js
CoffeeScript
61
star
10

ece-webtech-2022-fall

Materials for the WebTech course at ECE.
JavaScript
61
star
11

node-ron

Redis object relational mapper for NodeJs with a minimum of magic
CoffeeScript
58
star
12

ece-webtech-2023-fall

Supporting materials and labs for the Web Technologies course at ECE.
JavaScript
57
star
13

node-connect-coffee-script

Connect middleware to serve CoffeeScript files
CoffeeScript
56
star
14

node-plug-and-play

Easily create hooks and let users plug their own logic across your code to make it extensible by everyone with new features.
CoffeeScript
52
star
15

ece-devops-2023-fall

JavaScript
51
star
16

node-stream-transform

Object transformations implementing the Node.js `stream.Transform` API
49
star
17

ece-webtech-2021-fall

Materials for the Web technologies course at ECE.
JavaScript
44
star
18

node-pad

Left and right string padding for NodeJs
JavaScript
43
star
19

node-krb5

Kerberos native library for Node.js
C++
34
star
20

ece-devops-2020-fall

Materials for the DevOps course at the ECE.
JavaScript
32
star
21

node-thrift-hive

Hive client using the Apache Thrift RPC system
Thrift
28
star
22

ece-devops-2021-fall

JavaScript
28
star
23

node-each

Chained and parallel async iterator in one elegant function
CoffeeScript
25
star
24

jumbo

🐘 A local Hadoop cluster bootstrapper using Vagrant, Ansible, and Ambari.
Python
19
star
25

ece-bigdata-2023-spring

Python
17
star
26

node-shell

Command line arguments parser and stringifier
CoffeeScript
15
star
27

ece-devops-2023-fall-corrections

JavaScript
15
star
28

node-masson

Module execution engine for cluster deployments.
CoffeeScript
14
star
29

ece-devops-2023-spring-app

JavaScript
11
star
30

dsti-mlops-2023-spring

Jupyter Notebook
11
star
31

node-csv-docs

Website for the csv projects
JavaScript
10
star
32

ece-spark-2023-fall

Content for the Spark's course at ECE in fall 2023
Jupyter Notebook
9
star
33

spark-streaming-pyspark

Build and run Spark Structured Streaming pipelines in Hadoop - project using PySpark.
Python
9
star
34

dsti-bigdata-2023-spring

dsti-bigdata-2023-spring
Jupyter Notebook
9
star
35

cs-bigdata-2023-spring

Jupyter Notebook
8
star
36

ece-versioning-2022

Materials for the "Versioning" class at ECE.
7
star
37

ece-spark-2021-fall

Material for Data Engineering with Spark.
Jupyter Notebook
7
star
38

ece-webtech-2023-spring-app

JavaScript
7
star
39

ece-bigdata-2022-fall

Resources for ECE Big Data course
HiveQL
6
star
40

dsti-mlops-2022-autumn

Jupyter Notebook
6
star
41

node-ssh2-exec

Transparent use of `child_process.exec` and `ssh2.prototype.exec`
JavaScript
6
star
42

spark-mllib-streaming

Build Spark MLlib pipeline and integrate it with Spark Structured Streaming pipeline running in Hadoop - project using Scala
Scala
6
star
43

node-ssh2-fs

Transparent use of the `fs` module locally or over SSH
CoffeeScript
5
star
44

spark-streaming-scala

Build, run, and test Spark Structured Streaming pipelines in Hadoop - project using Scala
Scala
5
star
45

dsti-devops-2023-spring

JavaScript
5
star
46

ece-bigdata-2024-spring-app

Courses content for the 2024 Apprentis ECE class
Python
5
star
47

ece-versioning-2022-fall

versionning course
4
star
48

formations

CSS
4
star
49

ece-bigdata2-2023-fall

Lectures and labs for big data 2 classes
Jupyter Notebook
4
star
50

esgf-2020-fall-bigdata

HTML
4
star
51

ece-webtech-2022-spring

JavaScript
3
star
52

node-hadoop

The HTTP REST API supports the complete FileSystem interface for HDFS
CoffeeScript
3
star
53

node-ssh2-connect

Callback-based api behind ssh2 to open an SSH connection
CoffeeScript
3
star
54

dsti_2022_s22_1

Jupyter Notebook
3
star
55

ece-spark-2020-fall

Resources of "Data Engineering with Spark" course of ECE Paris
Python
3
star
56

dsti-mlops-2021-spring

Resources for MLOps course @ DSTI (spring 2021).
Jupyter Notebook
3
star
57

esgf-bigdata-2022-fall

Introduction to Big Data
HiveQL
3
star
58

node-mixme

A library for recursive merging of Javascript objects
TypeScript
3
star
59

node-nikita-arch

CoffeeScript
3
star
60

node-nikita-docs

Nikita Official website
JavaScript
2
star
61

cs-bigdata-2021-spring

Jupyter Notebook
2
star
62

ece-devops

ECE DevOps class resources
Ruby
2
star
63

dsti-devops-2021

JavaScript
2
star
64

ece-spark-2022-fall

Jupyter Notebook
2
star
65

dsti-devops-2020-fall

JavaScript
2
star
66

dsti-bigdata-2022-spring

Jupyter Notebook
2
star
67

dsti-devops-2022-fall

JavaScript
2
star
68

node-redac

JavaScript
2
star
69

dsti-mlops-2022-spring

The material for MLOps courses and labs.
Jupyter Notebook
2
star
70

we-are-hiring

Join Adaltas and build open source big data architectures
1
star
71

dsti_spoc

Course for DSTI SPOC students
Jupyter Notebook
1
star
72

dsti-devops-2022-spring

JavaScript
1
star
73

dsti-mlops-2023-autumn

Jupyter Notebook
1
star
74

spnego_world

C
1
star
75

node-ssh2-they

Extends Mocha with the function `they` to transparently run tests in local and ssh mode
CoffeeScript
1
star
76

dsti-devops-2022-autumn

JavaScript
1
star
77

ece-bigdata-2022-spring

Python
1
star
78

keyser

Keyser - encryption key and certificate management
Shell
1
star
79

gatsby-custom-graphql-schema

Gatsby bloging website with the custom GraphQL schema
JavaScript
1
star
80

rss-feeds-subscription

RSS Feeds for technology watch
1
star
81

remark-gatsby-plugins

A selection of Gatsby plugins developed and used by Adaltas
JavaScript
1
star
82

support-ukrain

1
star
83

node-prink

Human Readable pretty convertions (stringify, parse, compare) for filesize, file mode...
CoffeeScript
1
star
84

dsti-devops-2020-fall-iac

Vagrant and Ansible lab
1
star
85

ece-devops-2022-spring

Materials for the DevOps course at ECE.
JavaScript
1
star
86

demo-dbnomics-graphql

Expose the DBnomics REST API with a GraphQL interface using the GraphiQL UI.
JavaScript
1
star
87

ece-spark

Coding resources for the ECE Paris Spark course
Python
1
star
88

dsti-generate

Generate datasets with random data.
CoffeeScript
1
star
89

dsti-devops-2023-fall

JavaScript
1
star