Fast, unopinionated, minimalist web framework for node. expressjs.com
Go to file
Jon Church 723b5451bb
Throw on invalid status codes (#4212)
* check status code is integer, or string integer, in range

* fix tests, update jsdoc comment for res.status

* throw if number is string

* narrow valid range to between 1xx and 5xx

* disambiguate the error message

* update skipped tests, remove invalid string test

* remove invalid float test

* fixup! remove invalid float test

* fix invalid range tests error assertions

* remove unused deprecate function

* add test to assert on 200.00 coming through as 200

this is the behavior of node's underlying HTTP module

* revert back to throwing only on > 999 and < 100

* update implementation for > 999

* add test for 700 status code

* update history with change

* update jsdoc

* clarify jsdoc comment

* one more round of jsdoc

* update 501 test

* add invalid status code test for res.sendStatus

* add test describe block for valid range

* fixup! add test describe block for valid range

* reduce the describe nesting

* switch to testing status 100, to avoid 100-continue behavior

* fix 900 test

* stringify code in thrown RangeError message

* remove accidentally duplicated res.status method

* fix error range message

Co-authored-by: Chris de Almeida <ctcpip@users.noreply.github.com>

* update sendStatus invalid code test to use sendStatus

---------

Co-authored-by: Chris de Almeida <ctcpip@users.noreply.github.com>
2024-07-30 14:49:13 -07:00
.github/workflows Merge tag '4.19.0' into 5.x 2024-03-20 21:14:00 -05:00
benchmarks docs: add documentation for benchmarks 2024-02-19 12:04:49 -05:00
examples Merge tag '4.19.0' into 5.x 2024-03-20 21:14:00 -05:00
lib Throw on invalid status codes (#4212) 2024-07-30 14:49:13 -07:00
test Throw on invalid status codes (#4212) 2024-07-30 14:49:13 -07:00
.editorconfig build: Add .editorconfig 2017-03-19 16:46:37 -04:00
.eslintignore lint: add eslint rules that cover editorconfig 2017-08-05 23:37:39 -04:00
.eslintrc.yml Drop support for Node.js below 4 2022-02-08 09:48:54 -05:00
.gitignore build: use nyc for test coverage 2022-02-07 23:08:12 -05:00
appveyor.yml Merge tag '4.19.0' into 5.x 2024-03-20 21:14:00 -05:00
Charter.md docs: fix typo in casing of HTTP 2022-04-08 03:42:09 -04:00
Code-Of-Conduct.md docs: add Code of Conduct 2020-04-07 01:35:34 -04:00
Collaborator-Guide.md docs: fix typos in Collaborator Guide 2020-07-07 22:42:34 -04:00
Contributing.md docs: loosen TC activity rules 2024-03-14 12:43:12 +01:00
History.md Throw on invalid status codes (#4212) 2024-07-30 14:49:13 -07:00
index.js perf: enable strict mode 2015-06-18 23:01:18 -04:00
LICENSE Merge tag '3.20.0' 2015-02-18 22:33:47 -05:00
package.json call callback once on listen error 2024-05-17 13:47:56 -07:00
Readme-Guide.md docs: add guide for writing readmes 2017-02-20 18:21:38 -05:00
Readme.md docs: update git clone to https protocol 2022-11-01 21:05:31 -04:00
Release-Process.md Add note on how to update docs for new release (#5541) 2024-03-16 11:57:42 -06:00
Security.md docs: remove Node Security Project from security policy 2022-04-11 18:54:33 -04:00
Triager-Guide.md docs: fix typos in Triager Guide 2020-07-07 22:42:01 -04:00

Express Logo

Fast, unopinionated, minimalist web framework for Node.js.

NPM Version NPM Install Size NPM Downloads

const express = require('express')
const app = express()

app.get('/', function (req, res) {
  res.send('Hello World')
})

app.listen(3000)

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 0.10 or higher is required.

If this is a brand new project, make sure to create a package.json first with the npm init command.

Installation is done using the npm install command:

$ npm install express

Follow our installing guide for more information.

Features

  • Robust routing
  • Focus on high performance
  • Super-high test coverage
  • HTTP helpers (redirection, caching, etc)
  • View system supporting 14+ template engines
  • Content negotiation
  • Executable for generating applications quickly

Docs & Community

PROTIP Be sure to read Migrating from 3.x to 4.x as well as New features in 4.x.

Quick Start

The quickest way to get started with express is to utilize the executable express(1) to generate an application as shown below:

Install the executable. The executable's major version will match Express's:

$ npm install -g express-generator@4

Create the app:

$ express /tmp/foo && cd /tmp/foo

Install dependencies:

$ npm install

Start the server:

$ npm start

View the website at: http://localhost:3000

Philosophy

The Express philosophy is to provide small, robust tooling for HTTP servers, making it a great solution for single page applications, websites, hybrids, or public HTTP APIs.

Express does not force you to use any specific ORM or template engine. With support for over 14 template engines via Consolidate.js, you can quickly craft your perfect framework.

Examples

To view the examples, clone the Express repo and install the dependencies:

$ git clone https://github.com/expressjs/express.git --depth 1
$ cd express
$ npm install

Then run whichever example you want:

$ node examples/content-negotiation

Contributing

Linux Build Windows Build Test Coverage

The Express.js project welcomes all constructive contributions. Contributions take many forms, from code for bug fixes and enhancements, to additions and fixes to documentation, additional tests, triaging incoming pull requests and issues, and more!

See the Contributing Guide for more technical details on contributing.

Security Issues

If you discover a security vulnerability in Express, please see Security Policies and Procedures.

Running Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

People

The original author of Express is TJ Holowaychuk

The current lead maintainer is Douglas Christopher Wilson

List of all contributors

License

MIT