docs: only express v2

This commit is contained in:
Sebastian Beltran
2025-01-29 10:02:20 -05:00
parent 899dbfd011
commit 05a3ad7413
1087 changed files with 646 additions and 95554 deletions

View File

@@ -1,36 +0,0 @@
#!/bin/bash
DEST="../../en/resources/contributing.md"
# This script replaces the contents of a section with the contents from
# the annotated source address.
level=''
src=''
while IFS= read -r line; do
if [[ -n "$src" ]] && [[ "$line" != '#'* || "$line" == "$level"'#'* ]]; then
continue
fi
src=''
if [[ "$line" == '#'* ]]; then
title=${line##*\#}
level="${line:0:$((${#line} - ${#title}))}"
elif [[ "$line" == '<!-- SRC:'* ]]; then
src=${line:10}
src=${src% *}
fi
echo "$line"
if [[ -n "$src" ]]; then
echo
path=${src#* }
repo=${src% *}
curl -s "https://raw.githubusercontent.com/${repo}/master/${path}" | \
sed -En '/^##|^[^#]/,$p' | \
sed 's/^#/&'"${level:1}"'/g' | \
sed -E 's/(\[[^]]*\])\(([^):#]*)\)/\1(https:\/\/github.com\/'"$(sed 's/\//\\\//g' <<< "$repo")"'\/blob\/master\/\2)/g'
echo
fi
done <<<"$(< $DEST)" > $DEST

View File

@@ -1,20 +0,0 @@
import { readFile, writeFile } from 'node:fs/promises'
import path from 'node:path'
const NPMURL = 'https://registry.npmjs.org/express'
const response = await (await fetch(NPMURL)).json()
const { next, latest } = response['dist-tags']
try {
const filePath = path.resolve(path.join('..', '..', '_data', 'express.yml'))
let content = await readFile(filePath, 'utf8')
content = content.replace(/current_version: ".*"/, `current_version: "${latest}"`)
content = content.replace(/next_version: ".*"/, `next_version: "${next}"`)
await writeFile(filePath, content, 'utf8')
} catch (error) {
console.error('Error updating versions in _data/express.yml:', error)
}

View File

@@ -1,50 +0,0 @@
#!/bin/bash
# The following is a 3 column list of org, repo, and branch.
# - If the branch is NOT specified, then the README for that project
# will be pulled from npmjs.org instead and will reflect the latest
# release.
# - If the branch IS specified, it will be used to fetch the README.md
# from the given github repo. If that branch is NOT master, then the
# branch name will be appended to the local readme file name.
(cat <<LIST_END
expressjs body-parser master
expressjs compression master
expressjs connect-rid master
expressjs cookie-parser master
expressjs cookie-session master
expressjs cors master
expressjs errorhandler master
expressjs method-override master
expressjs morgan master
expressjs multer master
expressjs response-time master
expressjs serve-favicon master
expressjs serve-index master
expressjs serve-static master
expressjs session master
expressjs timeout master
expressjs vhost master
expressjs express master/examples
LIST_END
) | while read org repo branch; do
# Write the README.md to a file named after the repo
DEST="../../_includes/readmes/$repo.md"
# When fetching from a branch of a gh repo
GHURL="https://raw.githubusercontent.com/$org/$repo/$branch/README.md"
# When fetching from the latest release of a node module
NPMURL="https://registry.npmjs.org/$repo"
if [ -z "$branch" ]; then
# No branch means latest release, so fetch from npmjs.org
echo "fetching $org/$repo from latest npmjs.org release..."
curl -s $NPMURL | jq -r '.readme|rtrimstr("\n")' > $DEST
else
# This allows us to specify a branch other than master if we want to.
# In this case, the branch name is added to the readme name in the filename.
if [ "$branch" != "master" ]; then
DEST="../../_includes/readmes/$repo-$branch.md"
fi
echo "fetching $org/$repo/$branch from GitHub's raw content domain..."
curl -s $GHURL > $DEST
fi
done

View File

@@ -1,40 +0,0 @@
name: ci
on:
pull_request:
branches:
- gh-pages
push:
branches:
- gh-pages
pull_request_review:
types: [submitted]
jobs:
test:
runs-on: ubuntu-latest
if: |
github.event.pull_request.draft != true &&
(github.event_name == 'pull_request_review' && github.event.review.state == 'approved') ||
github.event_name != 'pull_request_review'
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Node.js dependencies
run: npm install
- name: Run tests
shell: bash
run: npm test
- name: Check Docker support
shell: bash
run: |
docker --version
make build

View File

@@ -1,38 +0,0 @@
name: Update External Docs
on:
workflow_dispatch:
schedule:
- cron: '0 8 * * 1'
permissions:
pull-requests: write
contents: write
jobs:
update-docs:
runs-on: ubuntu-latest
if: github.repository_owner == 'expressjs'
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Run scripts
working-directory: .github/scripts
run: |
bash ./get-contributing.sh
bash ./get-readmes.sh
node ./get-express-version.mjs
- name: Create Pull Request
uses: gr2m/create-or-update-pull-request-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commit-message: update external docs
title: 'Update external docs'
body: >
This auto-generated PR updates external documentation to the expressjs.com repository.
labels: doc
team_reviewers: expressjs/docs-captains
branch: external-docs-${{ github.sha }}

View File

@@ -1 +0,0 @@
3.3.5

12
404.md
View File

@@ -1,12 +0,0 @@
---
layout: 404
title: Page not found
description: We couldnt find the page youre looking for.
lang: en
---
# {{ page.title }}
We couldnt find the page youre looking for. Check the address or [head back home](/).
If this is a mistake, [let us know](https://github.com/expressjs/expressjs.com/issues/new/), and we will try to fix it!

View File

@@ -1,55 +0,0 @@
## Contributing to expressjs.com
This repository is only for issues related to the website [http://expressjs.com](http://expressjs.com). For issues related to Express, the framework, go to [https://github.com/expressjs/express](https://github.com/expressjs/express).
Feel free to make changes to the template files or the document files. The supporting docs are located in their respective directories, and the API docs are located under the `_includes` directory.
Content on this site is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License. See https://creativecommons.org/licenses/by-sa/3.0/us/ for a layman's summary;
See [LICENSE.md](LICENSE.md) for the full license.
## Contributing translations
We highly encourage community translations! We no longer have professional translations, and we believe in the power of our community to provide accurate and helpful translations.
The documentation is translated into these languages:
- English (`en`)
- Spanish (`es`)
- French (`fr`)
- Italian (`it`)
- Indonesian (`id`)
- Japanese (`ja`)
- Korean (`ko`)
- Brazilian Portuguese (`pt-br`)
- Russian (`ru`)
- Slovak (`sk`)
- Thai (`th`)
- Turkish (`tr`)
- Ukrainian (`uk`)
- Uzbek (`uz`)
- Simplified Chinese (`zh-cn`)
- Traditional Chinese (`zh-tw`)
To find translations that need to be done, you can [filter for merged PRs](https://github.com/expressjs/expressjs.com/pulls?q=is%3Apr+is%3Aclosed+label%3Arequires-translation-es) that include the tag for your language, such as `requires-translation-es`.
When you contribute a translation, please reference the original PR. This helps the person merging your translation to remove the `requires-translation-es` tag from the original PR.
### Adding new translations
To contribute a translation into another language, following the procedure below.
Follow these steps:
0. Clone the [`expressjs.com` repository](https://github.com/expressjs/expressjs.com)
1. Create a directory for the language of your choice using its [ISO 639-1 code](http://www.loc.gov/standards/iso639-2/php/code_list.php) as its name.
2. Copy `index.md`, `api.md`, `starter/`, `guide/`, `advanced/`, `resources/`, `4x/`, and `3x/`, to the language directory.
3. Remove the link to 2.x docs from the "API Reference" menu.
4. Update the `lang` variable in the copied markdown files.
5. Update the `title` variable in the copied markdown files.
6. Create the header, footer, notice, and announcement file for the language in the `_includes/` directory, in the respective directories, and make necessary edits to the contents.
7. Create the announcement file for the language in the `_includes/` directory.
9. Make sure to append `/{{ page.lang }}` to all the links within the site.
10. Update the `CONTRIBUTING.md` and the `.github/workflows/translation.yml` files with the new language
Thank you for your interest in contributing to expressjs.com. Your efforts help make our documentation accessible to everyone!

View File

@@ -1,27 +0,0 @@
# Use the official Ruby image as the base
FROM ruby:3.3.5
# Install Jekyll and Bundler
RUN gem install jekyll bundler
# Set the working directory
WORKDIR /usr/src/app
# Change the permissions of the working directory
RUN chmod 777 /usr/src/app
# Copy the Gemfile into the image
COPY Gemfile ./
COPY Gemfile.lock ./
# Install the gems
RUN bundle install --no-cache
# Copy the rest of the project into the image
COPY . .
# Expose the port Jekyll will run on
EXPOSE 4000
# The default command to run Jekyll
CMD ["jekyll", "serve", "--host", "0.0.0.0", "--livereload"]

View File

@@ -1,7 +0,0 @@
source 'https://rubygems.org'
ruby '3.3.5'
gem 'github-pages', group: :jekyll_plugins
gem 'webrick'

View File

@@ -1,282 +0,0 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.2.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
base64 (0.2.0)
bigdecimal (3.1.8)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.12.2)
colorator (1.1.0)
commonmarker (0.23.10)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
csv (3.3.0)
dnsruby (1.72.2)
simpleidn (~> 0.2.1)
drb (2.2.1)
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
ethon (0.16.0)
ffi (>= 1.15.0)
eventmachine (1.2.7)
execjs (2.9.1)
faraday (2.11.0)
faraday-net_http (>= 2.0, < 3.4)
logger
faraday-net_http (3.3.0)
net-http
ffi (1.17.0-x64-mingw-ucrt)
ffi (1.17.0-x86_64-linux-gnu)
forwardable-extended (2.6.0)
gemoji (4.1.0)
github-pages (232)
github-pages-health-check (= 1.18.2)
jekyll (= 3.10.0)
jekyll-avatar (= 0.8.0)
jekyll-coffeescript (= 1.2.2)
jekyll-commonmark-ghpages (= 0.5.1)
jekyll-default-layout (= 0.1.5)
jekyll-feed (= 0.17.0)
jekyll-gist (= 1.5.0)
jekyll-github-metadata (= 2.16.1)
jekyll-include-cache (= 0.2.1)
jekyll-mentions (= 1.6.0)
jekyll-optional-front-matter (= 0.3.2)
jekyll-paginate (= 1.1.0)
jekyll-readme-index (= 0.3.0)
jekyll-redirect-from (= 0.16.0)
jekyll-relative-links (= 0.6.1)
jekyll-remote-theme (= 0.4.3)
jekyll-sass-converter (= 1.5.2)
jekyll-seo-tag (= 2.8.0)
jekyll-sitemap (= 1.4.0)
jekyll-swiss (= 1.0.0)
jekyll-theme-architect (= 0.2.0)
jekyll-theme-cayman (= 0.2.0)
jekyll-theme-dinky (= 0.2.0)
jekyll-theme-hacker (= 0.2.0)
jekyll-theme-leap-day (= 0.2.0)
jekyll-theme-merlot (= 0.2.0)
jekyll-theme-midnight (= 0.2.0)
jekyll-theme-minimal (= 0.2.0)
jekyll-theme-modernist (= 0.2.0)
jekyll-theme-primer (= 0.6.0)
jekyll-theme-slate (= 0.2.0)
jekyll-theme-tactile (= 0.2.0)
jekyll-theme-time-machine (= 0.2.0)
jekyll-titles-from-headings (= 0.5.3)
jemoji (= 0.13.0)
kramdown (= 2.4.0)
kramdown-parser-gfm (= 1.1.0)
liquid (= 4.0.4)
mercenary (~> 0.3)
minima (= 2.5.1)
nokogiri (>= 1.16.2, < 2.0)
rouge (= 3.30.0)
terminal-table (~> 1.4)
webrick (~> 1.8)
github-pages-health-check (1.18.2)
addressable (~> 2.3)
dnsruby (~> 1.60)
octokit (>= 4, < 8)
public_suffix (>= 3.0, < 6.0)
typhoeus (~> 1.3)
html-pipeline (2.14.3)
activesupport (>= 2)
nokogiri (>= 1.4)
http_parser.rb (0.8.0)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
jekyll (3.10.0)
addressable (~> 2.4)
colorator (~> 1.0)
csv (~> 3.0)
em-websocket (~> 0.5)
i18n (>= 0.7, < 2)
jekyll-sass-converter (~> 1.0)
jekyll-watch (~> 2.0)
kramdown (>= 1.17, < 3)
liquid (~> 4.0)
mercenary (~> 0.3.3)
pathutil (~> 0.9)
rouge (>= 1.7, < 4)
safe_yaml (~> 1.0)
webrick (>= 1.0)
jekyll-avatar (0.8.0)
jekyll (>= 3.0, < 5.0)
jekyll-coffeescript (1.2.2)
coffee-script (~> 2.2)
coffee-script-source (~> 1.12)
jekyll-commonmark (1.4.0)
commonmarker (~> 0.22)
jekyll-commonmark-ghpages (0.5.1)
commonmarker (>= 0.23.7, < 1.1.0)
jekyll (>= 3.9, < 4.0)
jekyll-commonmark (~> 1.4.0)
rouge (>= 2.0, < 5.0)
jekyll-default-layout (0.1.5)
jekyll (>= 3.0, < 5.0)
jekyll-feed (0.17.0)
jekyll (>= 3.7, < 5.0)
jekyll-gist (1.5.0)
octokit (~> 4.2)
jekyll-github-metadata (2.16.1)
jekyll (>= 3.4, < 5.0)
octokit (>= 4, < 7, != 4.4.0)
jekyll-include-cache (0.2.1)
jekyll (>= 3.7, < 5.0)
jekyll-mentions (1.6.0)
html-pipeline (~> 2.3)
jekyll (>= 3.7, < 5.0)
jekyll-optional-front-matter (0.3.2)
jekyll (>= 3.0, < 5.0)
jekyll-paginate (1.1.0)
jekyll-readme-index (0.3.0)
jekyll (>= 3.0, < 5.0)
jekyll-redirect-from (0.16.0)
jekyll (>= 3.3, < 5.0)
jekyll-relative-links (0.6.1)
jekyll (>= 3.3, < 5.0)
jekyll-remote-theme (0.4.3)
addressable (~> 2.0)
jekyll (>= 3.5, < 5.0)
jekyll-sass-converter (>= 1.0, <= 3.0.0, != 2.0.0)
rubyzip (>= 1.3.0, < 3.0)
jekyll-sass-converter (1.5.2)
sass (~> 3.4)
jekyll-seo-tag (2.8.0)
jekyll (>= 3.8, < 5.0)
jekyll-sitemap (1.4.0)
jekyll (>= 3.7, < 5.0)
jekyll-swiss (1.0.0)
jekyll-theme-architect (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-cayman (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-dinky (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-hacker (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-leap-day (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-merlot (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-midnight (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-minimal (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-modernist (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-primer (0.6.0)
jekyll (> 3.5, < 5.0)
jekyll-github-metadata (~> 2.9)
jekyll-seo-tag (~> 2.0)
jekyll-theme-slate (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-tactile (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-theme-time-machine (0.2.0)
jekyll (> 3.5, < 5.0)
jekyll-seo-tag (~> 2.0)
jekyll-titles-from-headings (0.5.3)
jekyll (>= 3.3, < 5.0)
jekyll-watch (2.2.1)
listen (~> 3.0)
jemoji (0.13.0)
gemoji (>= 3, < 5)
html-pipeline (~> 2.2)
jekyll (>= 3.0, < 5.0)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
liquid (4.0.4)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.1)
mercenary (0.3.6)
minima (2.5.1)
jekyll (>= 3.5, < 5.0)
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
minitest (5.25.1)
net-http (0.4.1)
uri
nokogiri (1.16.7-x64-mingw-ucrt)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
octokit (4.25.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (5.1.1)
racc (1.8.1)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rexml (3.3.7)
rouge (3.30.0)
rubyzip (2.3.2)
safe_yaml (1.0.5)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
securerandom (0.3.1)
simpleidn (0.2.3)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (1.8.0)
uri (0.13.1)
webrick (1.8.1)
PLATFORMS
x64-mingw-ucrt
x86_64-linux
DEPENDENCIES
github-pages
webrick
RUBY VERSION
ruby 3.3.5p100
BUNDLED WITH
2.5.16

View File

@@ -1,27 +0,0 @@
GREEN := \033[1;32m
BLUE := \033[1;34m
RESET := \033[0m
# The directory of this file
DIR := $(shell echo $(shell cd "$(shell dirname "${BASH_SOURCE[0]}" )" && pwd ))
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## This help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "${GREEN}%-30s${RESET} %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
serve: ## Local server
@echo "${BLUE}Starting expressjs.com at http://localhost:4000${RESET}"
docker run -p 4000:4000 -p 35729:35729 -v $(DIR):/usr/src/app expressjs.com bundle exec jekyll serve --host 0.0.0.0
build: ## Build site
@echo "${BLUE}Building site...${RESET}"
docker build -t expressjs.com .
clean: ## Clean up
@echo "${BLUE}Clean up...${RESET}"
docker rmi expressjs.com

View File

@@ -1,82 +1,17 @@
# expressjs.com
# Express V2 Documentation
This is the repository of the website [expressjs.com](https://expressjs.com). It is hosted directly from the repository as a [GitHub Pages](https://pages.github.com/) website.
> [!CAUTION]
> Express 2.x IS END-OF-LIFE AND NO LONGER MAINTAINED
> If you are unable to upgrade past 2.x, please consider [Commercial Support Options](https://expressjs.com/en/support/#commercial-support-options)
## Local Setup
## Preview the website locally
To preview the website locally:
1. Install [Ruby and Bundler](https://help.github.com/articles/setting-up-your-pages-site-locally-with-jekyll/) if you don't have them already.
1. Install the [jekyll-redirect-from](https://github.com/jekyll/jekyll-redirect-from) gem:
```sh
$ gem install jekyll-redirect-from
```
1. Clone this repository by running the following command:
```sh
$ git clone https://github.com/expressjs/expressjs.com.git
```
1. Navigate to the cloned repository directory and run the following command:
```sh
$ bundle install
```
Bundler will look in the Gemfile for which gems to install. The `github-pages` gem includes the same version of Jekyll and other dependencies as used by GitHub Pages, so that your local setup mirrors GitHub Pages as closely as possible.
1. Run Jekyll using the following command:
```sh
$ bundle exec jekyll serve
```
Then, load <http://localhost:4000> in your browser.
## Local Setup using Docker
>[!TIP]
> You can run `make help` to obtain detailed information on how to use our make commands.
0. Ensure that you have Docker and Make installed.
1. Run `make build` to build the project.
2. Run `make serve` to serve the project, this include live reloading so any change will be reflected (it can take a while, check the logs).
3. Run `make clean` to remove the docker images and resources generated.
## Formatting
Jekyll uses a variant of Markdown known as [Kramdown](https://kramdown.gettalong.org/quickref.html).
Jekyll uses the [Liquid template engine](http://liquidmarkup.org/) for templating.
You can use [GFM](https://kramdown.gettalong.org/parser/gfm.html) fenced code blocks for JavaScript; for example:
<pre>
```js
var express = require('express')
var app = express()
app.listen(3000)
```
</pre>
The result looks like this:
```js
const express = require('express')
const app = express()
app.listen(3000)
```
The default GitHub Pages syntax highlighting has been disabled in `_config.yml` to allow highlighting with [prism.js](https://prismjs.com/).
0. Clone this repository `git clone https://github.com/expressjs/expressjs.com.git --single-branch --branch 2x`
1. Install [Node.js](https://nodejs.org/en/download/).
2. Run `npm install` to install the dependencies.
3. Run `npm run preview` to start the server.
4. Open `http://localhost:3000` in your browser.
## Contributing
Feel free to make changes to the template files or the document files. The supporting docs are located in their respective directories, and the API docs are located under the `_includes` directory.
Please see the [Contributors' Guide](CONTRIBUTING.md) for more information on contributing to the documentation, including information on contributing translations.
## Why use Jekyll instead of an Express-based solution?
Jekyll comes built-in with GitHub Pages. Since we are already using GitHub Pages to host the website, it makes sense to leverage the capabilities it provides. It's all about using the right tool, for the right job, under the right circumstances.
Please see the [Contributors' Guide](https://github.com/expressjs/expressjs.com/blob/gh-pages/CONTRIBUTING.md) for more information on contributing to the documentation, including information on contributing translations.

View File

@@ -1,31 +0,0 @@
# Site settings
defaults:
-
scope:
path: "_posts"
type: "posts"
values:
layout: "post"
menu: blog
lang: en
# Build settings
markdown: kramdown
plugins:
- jekyll-redirect-from
kramdown:
input: GFM
hard_wrap: false
syntax_highlighter_opts:
disable : true
exclude:
- [uk/CHANGELOG.md]
- vendor/bundle
- node_modules/
github: [metadata]

View File

@@ -1,3 +0,0 @@
# config: https://github.com/algolia/docsearch-configs/blob/master/configs/expressjs.json
apiKey: 7164e33055faa6ecddefd9e08fc59f5d
indexName: expressjs

View File

@@ -1,2 +0,0 @@
current_version: "4.21.2"
next_version: "5.0.1"

View File

@@ -1,4 +0,0 @@
<div class="doc-box doc-notice" markdown="1"><p class="doc-notice-title"><i class="fa fa-lg fa-exclamation-triangle"></i> Caution</p>
{{include.content}}
</div>

View File

@@ -1,3 +0,0 @@
<div class="doc-box doc-info" markdown="1"><p class="doc-info-title"><i class="fa fa-lg fa-info-circle"></i> Note</p>
{{include.content}}
</div>

View File

@@ -1,4 +0,0 @@
<div class="doc-box doc-warn" markdown="1">
<p class="doc-warn-title"><svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor"><path d="M12 7C11.7348 7 11.4804 7.10536 11.2929 7.29289C11.1054 7.48043 11 7.73478 11 8V12C11 12.2652 11.1054 12.5196 11.2929 12.7071C11.4804 12.8946 11.7348 13 12 13C12.2652 13 12.5196 12.8946 12.7071 12.7071C12.8946 12.5196 13 12.2652 13 12V8C13 7.73478 12.8946 7.48043 12.7071 7.29289C12.5196 7.10536 12.2652 7 12 7ZM12 15C11.8022 15 11.6089 15.0586 11.4444 15.1685C11.28 15.2784 11.1518 15.4346 11.0761 15.6173C11.0004 15.8 10.9806 16.0011 11.0192 16.1951C11.0578 16.3891 11.153 16.5673 11.2929 16.7071C11.4327 16.847 11.6109 16.9422 11.8049 16.9808C11.9989 17.0194 12.2 16.9996 12.3827 16.9239C12.5654 16.8482 12.7216 16.72 12.8315 16.5556C12.9414 16.3911 13 16.1978 13 16C13 15.7348 12.8946 15.4804 12.7071 15.2929C12.5196 15.1054 12.2652 15 12 15ZM21.71 7.56L16.44 2.29C16.2484 2.10727 15.9948 2.00368 15.73 2H8.27C8.00523 2.00368 7.75163 2.10727 7.56 2.29L2.29 7.56C2.10727 7.75163 2.00368 8.00523 2 8.27V15.73C2.00368 15.9948 2.10727 16.2484 2.29 16.44L7.56 21.71C7.75163 21.8927 8.00523 21.9963 8.27 22H15.73C15.9948 21.9963 16.2484 21.8927 16.44 21.71L21.71 16.44C21.8927 16.2484 21.9963 15.9948 22 15.73V8.27C21.9963 8.00523 21.8927 7.75163 21.71 7.56ZM20 15.31L15.31 20H8.69L4 15.31V8.69L8.69 4H15.31L20 8.69V15.31Z"></path></svg> Warning</p>
{{include.content}}
</div>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,8 +0,0 @@
<ul>
<li>
<p class="announcement-title">{% include icons/announcement.svg %} Express 5.0 documentation is now available.</p>
<p markdown="1">
The <a href="{{ page.lang }}/5x/api.html">API documentation</a> is a work in progress. For information on what's in the release, see the Express <a href="https://github.com/expressjs/express/blob/5.0/History.md">release history</a>.
</p>
</li>
</ul>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,8 +0,0 @@
<ul>
<li>
<p class="announcement-title">{% include icons/announcement.svg %} Dokumentasi Express 5.0 versi beta kini telah tersedia.</p>
<p markdown="1">
<a href="{{ page.lang }}/5x/api.html">Dokumentasi API</a> beta masih dalam proses. Untuk informasi tentang apa yang ada dalam rilis, lihat <a href="https://github.com/expressjs/express/blob/5.0/History.md">riwayat rilis</a> Express.
</p>
</li>
</ul>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,9 +0,0 @@
<ul>
<li>
<p class="announcement-title">{% include icons/announcement.svg %} A documentação do Express 5.0 já está disponível.</p>
<p markdown="1">
<!-- we still haven't a 5x doc for pt-br -->
A <a href="/5x/api.html">documentação da API</a> está em andamento. Para obter informações sobre o que há no lançamento, consulte o <a href="https://github.com/expressjs/express/blob/5.0/History.md">histórico de lançamentos</a> do Express.
</p>
</li>
</ul>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,8 +0,0 @@
<ul>
<li>
<p class="announcement-title">{% include icons/announcement.svg %} Express รุ่น 4.16.0 มีคุณลักษณะความปลอดภัยล่าสุดที่สำคัญ</p>
<p markdown="1">
สำหรับข้อมูลว่าอะไรเพิ่มเติมบ้างในรุ่นนี้ สามารถดูใน [บันทึกการเปลี่ยนแปลง 4.16.0](/{{ page.lang }}/changelog/4x.html#4.16.0).
</p>
</li>
</ul>

View File

@@ -1,8 +0,0 @@
<ul>
<li>
<p class="announcement-title">{% include icons/announcement.svg %} Express 4.16.0 mevcut sürümdür.</p>
<p markdown="1">
Bu sürümde nelerin eklendiği hakkında daha fazla bilgi almak için [4.16.0 changelog](/{{ page.lang }}/changelog/4x.html#4.16.0).
</p>
</li>
</ul>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,8 +0,0 @@
<ul>
<li>
<p class="announcement-title">{% include icons/announcement.svg %} Express 4.16.0 reliz qilindi</p>
<p markdown="1">
Express 4.16.0 da ko'plab xatolar to'g'irlandi, xavfsizlikni ta'minlash uchun o'zgarishlar kiritildi, ishlash unumdorligi oshirildi va boshqa yangi imkoniyatlar qo'shildi. To'liq ma'lumot uchun [4.16.0 changelog](/en/changelog/4x.html#4.16.0).
</p>
</li>
</ul>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,16 +0,0 @@
<ul>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Ut enim ad minim veniam</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
</li>
<li>
<p><time datetime="2015-05-15 19:00">May 5, 2015</time> Excepteur sint occaecat cupidatat non proident</p>
<p>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</li>
</ul>

View File

@@ -1,57 +0,0 @@
<h3 id='app.VERB'>app.VERB(path, [callback...], callback)</h3>
The `app.VERB()` methods provide the routing functionality
in Express, where <strong>VERB</strong> is one of the HTTP verbs, such
as `app.post()`. Multiple callbacks may be given, all are treated
equally, and behave just like middleware, with the one exception that
these callbacks may invoke `next('route')` to bypass the
remaining route callback(s). This mechanism can be used to perform pre-conditions
on a route then pass control to subsequent routes when there is no reason to proceed
with the route matched.
The following snippet illustrates the most simple route definition possible. Express
translates the path strings to regular expressions, used internally to match incoming requests.
Query strings are <em>not</em> considered when peforming these matches, for example "GET /"
would match the following route, as would "GET /?name=tobi".
```js
app.get('/', function (req, res) {
res.send('hello world')
})
```
Regular expressions may also be used, and can be useful
if you have very specific restraints, for example the following
would match "GET /commits/71dbb9c" as well as "GET /commits/71dbb9c..4c084f9".
```js
app.get(/^\/commits\/(\w+)(?:\.\.(\w+))?$/, function (req, res) {
var from = req.params[0]
var to = req.params[1] || 'HEAD'
res.send('commit range ' + from + '..' + to)
})
```
Several callbacks may also be passed, useful for re-using middleware
that load resources, perform validations, etc.
```js
app.get('/user/:id', user.load, function () {
// ...
})
```
These callbacks may be passed within arrays as well, these arrays are
simply flattened when passed:
```js
var middleware = [loadForum, loadThread]
app.get('/forum/:fid/thread/:tid', middleware, function () {
// ...
})
app.post('/forum/:fid/thread/:tid', middleware, function () {
// ...
})
```

View File

@@ -1,32 +0,0 @@
<h3 id='app.all'>app.all(path, [callback...], callback)</h3>
This method functions just like the `app.VERB()` methods,
however it matches all HTTP verbs.
This method is extremely useful for
mapping "global" logic for specific path prefixes or arbitrary matches.
For example if you placed the following route at the top of all other
route definitions, it would require that all routes from that point on
would require authentication, and automatically load a user. Keep in mind
that these callbacks do not have to act as end points, `loadUser`
can perform a task, then `next()` to continue matching subsequent
routes.
```js
app.all('*', requireAuthentication, loadUser)
```
Or the equivalent:
```js
app.all('*', requireAuthentication)
app.all('*', loadUser)
```
Another great example of this is white-listed "global" functionality. Here
the example is much like before, however only restricting paths prefixed with
"/api":
```js
app.all('/api/*', requireAuthentication)
```

View File

@@ -1,40 +0,0 @@
<h3 id='app.configure'>app.configure([env], callback)</h3>
Conditionally invoke `callback` when `env` matches `app.get('env')`,
aka `process.env.NODE_ENV`. This method remains for legacy reasons, and is effectively
an `if` statement as illustrated in the following snippets. These functions are <em>not</em>
required in order to use `app.set()` and other configuration methods.
```js
// all environments
app.configure(function () {
app.set('title', 'My Application')
})
// development only
app.configure('development', function () {
app.set('db uri', 'localhost/dev')
})
// production only
app.configure('production', function () {
app.set('db uri', 'n.n.n.n/prod')
})
```
Is effectively sugar for:
```js
// all environments
app.set('title', 'My Application')
// development only
if (app.get('env') === 'development') {
app.set('db uri', 'localhost/dev')
}
// production only
if (app.get('env') === 'production') {
app.set('db uri', 'n.n.n.n/prod')
}
```

View File

@@ -1,9 +0,0 @@
<h3 id='app.disable'>app.disable(name)</h3>
Set setting `name` to `false`.
```js
app.disable('trust proxy')
app.get('trust proxy')
// => false
```

View File

@@ -1,12 +0,0 @@
<h3 id='app.disabled'>app.disabled(name)</h3>
Check if setting `name` is disabled.
```js
app.disabled('trust proxy')
// => true
app.enable('trust proxy')
app.disabled('trust proxy')
// => false
```

View File

@@ -1,9 +0,0 @@
<h3 id='app.enable'>app.enable(name)</h3>
Set setting `name` to `true`.
```js
app.enable('trust proxy')
app.get('trust proxy')
// => true
```

View File

@@ -1,12 +0,0 @@
<h3 id='app.enabled'>app.enabled(name)</h3>
Check if setting `name` is enabled.
```js
app.enabled('trust proxy')
// => false
app.enable('trust proxy')
app.enabled('trust proxy')
// => true
```

View File

@@ -1,39 +0,0 @@
<h3 id='app.engine'>app.engine(ext, callback)</h3>
Register the given template engine `callback` as `ext`
By default will `require()` the engine based on the
file extension. For example if you try to render
a "foo.jade" file Express will invoke the following internally,
and cache the `require()` on subsequent calls to increase
performance.
```js
app.engine('jade', require('jade').__express)
```
For engines that do not provide `.__express` out of the box -
or if you wish to "map" a different extension to the template engine
you may use this method. For example mapping the EJS template engine to
".html" files:
```js
app.engine('html', require('ejs').renderFile)
```
In this case EJS provides a `.renderFile()` method with
the same signature that Express expects: `(path, options, callback)`,
though note that it aliases this method as `ejs.__express` internally
so if you're using ".ejs" extensions you dont need to do anything.
Some template engines do not follow this convention, the
<a href="https://github.com/visionmedia/consolidate.js">consolidate.js</a>
library was created to map all of node's popular template
engines to follow this convention, thus allowing them to
work seemlessly within Express.
```js
var engines = require('consolidate')
app.engine('haml', engines.haml)
app.engine('html', engines.hogan)
```

View File

@@ -1,12 +0,0 @@
<h3 id='app.get'>app.get(name)</h3>
Get setting `name` value.
```js
app.get('title')
// => undefined
app.set('title', 'My Site')
app.get('title')
// => "My Site"
```

View File

@@ -1,36 +0,0 @@
<h3 id='app.listen'>app.listen()</h3>
Bind and listen for connections on the given host and port,
this method is identical to node's <a href="http://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback">http.Server#listen()</a>.
```js
var express = require('express')
var app = express()
app.listen(3000)
```
The `app` returned by `express()` is in fact a JavaScript
`Function`, designed to be passed to node's http servers as a callback
to handle requests. This allows you to provide both HTTP and HTTPS versions of
your app with the same codebase easily, as the app does not inherit from these,
it is simply a callback:
```js
var express = require('express')
var https = require('https')
var http = require('http')
var app = express()
http.createServer(app).listen(80)
https.createServer(options, app).listen(443)
```
The `app.listen()` method is simply a convenience method defined as,
if you wish to use HTTPS or provide both, use the technique above.
```js
app.listen = function () {
var server = http.createServer(this)
return server.listen.apply(server, arguments)
}
```

View File

@@ -1,47 +0,0 @@
<h3 id='app.locals'>app.locals</h3>
Application local variables are provided to all templates
rendered within the application. This is useful for providing
helper functions to templates, as well as app-level data.
```js
app.locals.title = 'My App'
app.locals.strftime = require('strftime')
```
The `app.locals` object is a JavaScript `Function`,
which when invoked with an object will merge properties into itself, providing
a simple way to expose existing objects as local variables.
```js
app.locals({
title: 'My App',
phone: '1-250-858-9990',
email: 'me@myapp.com'
})
console.log(app.locals.title)
// => 'My App'
console.log(app.locals.email)
// => 'me@myapp.com'
```
A consequence of the `app.locals` Object being ultimately a Javascript Function Object is that you must not reuse existing (native) named properties for your own variable names, such as `name, apply, bind, call, arguments, length, constructor`.
```js
app.locals({ name: 'My App' })
console.log(app.locals.name)
// => return 'app.locals' in place of 'My App' (app.locals is a Function !)
// => if name's variable is used in a template, a ReferenceError will be returned.
```
The full list of native named properties can be found in many specifications. The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference">JavaScript specification</a> introduced original properties, some of which still recognized by modern engines, and the <a href="http://www.ecma-international.org/ecma-262/5.1/">EcmaScript specification</a> then built on it and normalized the set of properties, adding new ones and removing deprecated ones. Check out properties for Functions and Objects if interested.
By default Express exposes only a single app-level local variable, `settings`.
```js
app.set('title', 'My App')
// use settings.title in a view
```

View File

@@ -1,70 +0,0 @@
<h3 id='app.param'>app.param([name], callback)</h3>
Map logic to route parameters. For example when `:user`
is present in a route path you may map user loading logic to automatically
provide `req.user` to the route, or perform validations
on the parameter input.
The following snippet illustrates how the `callback`
is much like middleware, thus supporting async operations, however
providing the additional value of the parameter, here named as `id`.
An attempt to load the user is then performed, assigning `req.user`,
otherwise passing an error to `next(err)`.
```js
app.param('user', function (req, res, next, id) {
User.find(id, function (err, user) {
if (err) {
next(err)
} else if (user) {
req.user = user
next()
} else {
next(new Error('failed to load user'))
}
})
})
```
Alternatively you may pass only a `callback`, in which
case you have the opportunity to alter the `app.param()` API.
For example the <a href="http://github.com/expressjs/express-params">express-params</a>
defines the following callback which allows you to restrict parameters to a given
regular expression.
This example is a bit more advanced, checking if the second argument is a regular
expression, returning the callback which acts much like the "user" param example.
```js
app.param(function (name, fn) {
if (fn instanceof RegExp) {
return function (req, res, next, val) {
var captures
if ((captures = fn.exec(String(val)))) {
req.params[name] = captures
next()
} else {
next('route')
}
}
}
})
```
The method could now be used to effectively validate parameters, or also
parse them to provide capture groups:
```js
app.param('id', /^\d+$/)
app.get('/user/:id', function (req, res) {
res.send('user ' + req.params.id)
})
app.param('range', /^(\w+)\.\.(\w+)?$/)
app.get('/range/:range', function (req, res) {
var range = req.params.range
res.send('from ' + range[1] + ' to ' + range[2])
})
```

View File

@@ -1,15 +0,0 @@
<h3 id='app.render'>app.render(view, [options], callback)</h3>
Render a `view` with a callback responding with
the rendered string. This is the app-level variant of `res.render()`,
and otherwise behaves the same way.
```js
app.render('email', function (err, html) {
// ...
})
app.render('email', { name: 'Tobi' }, function (err, html) {
// ...
})
```

View File

@@ -1,29 +0,0 @@
<h3 id='app.routes'>app.routes</h3>
The `app.routes` object houses all of the routes defined mapped
by the associated HTTP verb. This object may be used for introspection capabilities,
for example Express uses this internally not only for routing but to provide default
<string>OPTIONS</string> behaviour unless `app.options()` is used. Your application
or framework may also remove routes by simply by removing them from this object.
The output of `console.log(app.routes)`:
```
{ get:
[ { path: '/',
method: 'get',
callbacks: [Object],
keys: [],
regexp: /^\/\/?$/i },
{ path: '/user/:id',
method: 'get',
callbacks: [Object],
keys: [{ name: 'id', optional: false }],
regexp: /^\/user\/(?:([^\/]+?))\/?$/i } ],
delete:
[ { path: '/user/:id',
method: 'delete',
callbacks: [Object],
keys: [Object],
regexp: /^\/user\/(?:([^\/]+?))\/?$/i } ] }
```

View File

@@ -1,9 +0,0 @@
<h3 id='app.set'>app.set(name, value)</h3>
Assigns setting `name` to `value`.
```js
app.set('title', 'My Site')
app.get('title')
// => "My Site"
```

View File

@@ -1,15 +0,0 @@
<h3 id='app-settings'>settings</h3>
The following settings are provided to alter how Express will behave:
* `env` Environment mode, defaults to process.env.NODE_ENV or "development"
* `trust proxy` Enables reverse proxy support, disabled by default
* `jsonp callback name` Changes the default callback name of ?callback=
* `json replacer` JSON replacer callback, null by default
* `json spaces` JSON response spaces for formatting, defaults to 2 in development, 0 in production
* `case sensitive routing` Enable case sensitivity, disabled by default, treating "/Foo" and "/foo" as the same
* `strict routing` Enable strict routing, by default "/foo" and "/foo/" are treated the same by the router
* `view cache` Enables view template compilation caching, enabled in production by default
* `view engine` The default engine extension to use when omitted
* `views` The view directory path, defaulting to "process.cwd() + '/views'"

View File

@@ -1,89 +0,0 @@
<h3 id='app.use'>app.use([path], function)</h3>
Use the given middleware `function`, with optional mount `path`,
defaulting to "/".
```js
var express = require('express')
var app = express()
// simple logger
app.use(function (req, res, next) {
console.log('%s %s', req.method, req.url)
next()
})
// respond
app.use(function (req, res, next) {
res.send('Hello World')
})
app.listen(3000)
```
The "mount" path is stripped and is <strong>not</strong> visible
to the middleware `function`. The main effect of this feature is that
mounted middleware may operate without code changes regardless of its "prefix"
pathname.
<div class="doc-box doc-notice" markdown="1">
A route will match any path that follows its path immediately with either a "`/`" or a "`.`". For example: `app.use('/apple', ...)` will match _/apple_, _/apple/images_, _/apple/images/news_, _/apple.html_, _/apple.html.txt_, and so on.
</div>
Here's a concrete example, take the typical use-case of serving files in ./public
using the `express.static()` middleware:
```js
// GET /javascripts/jquery.js
// GET /style.css
// GET /favicon.ico
app.use(express.static(path.join(__dirname, 'public')))
```
Say for example you wanted to prefix all static files with "/static", you could
use the "mounting" feature to support this. Mounted middleware functions are _not_
invoked unless the `req.url` contains this prefix, at which point
it is stripped when the function is invoked. This affects this function only,
subsequent middleware will see `req.url` with "/static" included
unless they are mounted as well.
```js
// GET /static/javascripts/jquery.js
// GET /static/style.css
// GET /static/favicon.ico
app.use('/static', express.static(path.join(__dirname, 'public')))
```
The order of which middleware are "defined" using `app.use()` is
very important, they are invoked sequentially, thus this defines middleware
precedence. For example usually `express.logger()` is the very
first middleware you would use, logging every request:
```js
app.use(express.logger())
app.use(express.static(path.join(__dirname, 'public')))
app.use(function (req, res) {
res.send('Hello')
})
```
Now suppose you wanted to ignore logging requests for static files, but to
continue logging routes and middleware defined after `logger()`,
you would simply move `static()` above:
```js
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.logger())
app.use(function (req, res) {
res.send('Hello')
})
```
Another concrete example would be serving files from multiple directories,
giving precedence to "./public" over the others:
```js
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.static(path.join(__dirname, 'files')))
app.use(express.static(path.join(__dirname, 'uploads')))
```

View File

@@ -1,69 +0,0 @@
<h2 id="application">Application</h2>
<section markdown="1">
{% include api/en/3x/app-set.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-get.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-enable.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-disable.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-enabled.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-disabled.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-configure.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-use.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-settings.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-engine.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-param.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-VERB.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-all.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-locals.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-render.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-routes.md %}
</section>
<section markdown="1">
{% include api/en/3x/app-listen.md %}
</section>

View File

@@ -1,14 +0,0 @@
<h2 id="express">express()</h2>
Creates an Express application. The `express()` function is a top-level function exported by the _express_ module.
```js
var express = require('express')
var app = express()
app.get('/', function (req, res) {
res.send('hello world')
})
app.listen(3000)
```

View File

@@ -1,161 +0,0 @@
<ul id="menu">
<li><a href="#express">express()</a></li>
<li id="app-api"> <a href="#application">Application</a>
<ul id="app-menu">
<li><a href="#app.set">app.set()</a>
</li>
<li><a href="#app.get">app.get()</a>
</li>
<li><a href="#app.enable">app.enable()</a>
</li>
<li><a href="#app.disable">app.disable()</a>
</li>
<li><a href="#app.enabled">app.enabled()</a>
</li>
<li><a href="#app.disabled">app.disabled()</a>
</li>
<li><a href="#app.configure">app.configure()</a>
</li>
<li><a href="#app.use">app.use()</a>
</li>
<li><a href="#app-settings">application settings</a>
</li>
<li><a href="#app.engine">app.engine()</a>
</li>
<li><a href="#app.param">app.param()</a>
</li>
<li><a href="#app.VERB">application routing</a>
</li>
<li><a href="#app.all">app.all()</a>
</li>
<li><a href="#app.locals">app.locals</a>
</li>
<li><a href="#app.render">app.render()</a>
</li>
<li><a href="#app.routes">app.routes</a>
</li>
<li><a href="#app.listen">app.listen()</a>
</li>
</ul>
</li>
<li id="req-api"> <a href="#request">Request</a>
<ul id="req-menu">
<li><a href="#req.params">req.params</a>
</li>
<li><a href="#req.query">req.query</a>
</li>
<li><a href="#req.body">req.body</a>
</li>
<li><a href="#req.files">req.files</a>
</li>
<li><a href="#req.param">req.param()</a>
</li>
<li><a href="#req.route">req.route</a>
</li>
<li><a href="#req.cookies">req.cookies</a>
</li>
<li><a href="#req.signedCookies">req.signedCookies</a>
</li>
<li><a href="#req.get">req.get()</a>
</li>
<li><a href="#req.accepts">req.accepts()</a>
</li>
<li><a href="#req.accepted">req.accepted</a>
</li>
<li><a href="#req.is">req.is()</a>
</li>
<li><a href="#req.ip">req.ip</a>
</li>
<li><a href="#req.ips">req.ips</a>
</li>
<li><a href="#req.path">req.path</a>
</li>
<li><a href="#req.host">req.host</a>
</li>
<li><a href="#req.fresh">req.fresh</a>
</li>
<li><a href="#req.stale">req.stale</a>
</li>
<li><a href="#req.xhr">req.xhr</a>
</li>
<li><a href="#req.protocol">req.protocol</a>
</li>
<li><a href="#req.secure">req.secure</a>
</li>
<li><a href="#req.subdomains">req.subdomains</a>
</li>
<li><a href="#req.originalUrl">req.originalUrl</a>
</li>
<li><a href="#req.acceptedLanguages">req.acceptedLanguages</a>
</li>
<li><a href="#req.acceptedCharsets">req.acceptedCharsets</a>
</li>
<li><a href="#req.acceptsCharset">req.acceptsCharset()</a>
</li>
<li><a href="#req.acceptsLanguage">req.acceptsLanguage()</a>
</li>
<li><a href="#req.res">req.res</a>
</li>
</ul>
</li>
<li id="res-api"> <a href="#response">Response</a>
<ul id="res-menu">
<li><a href="#res.status">res.status()</a>
</li>
<li><a href="#res.set">res.set()</a>
</li>
<li><a href="#res.get">res.get()</a>
</li>
<li><a href="#res.cookie">res.cookie()</a>
</li>
<li><a href="#res.clearCookie">res.clearCookie()</a>
</li>
<li><a href="#res.redirect">res.redirect()</a>
</li>
<li><a href="#res.location">res.location()</a>
</li>
<li><a href="#res.charset">res.charset</a>
</li>
<li><a href="#res.send">res.send()</a>
</li>
<li><a href="#res.json">res.json()</a>
</li>
<li><a href="#res.jsonp">res.jsonp()</a>
</li>
<li><a href="#res.type">res.type()</a>
</li>
<li><a href="#res.format">res.format()</a>
</li>
<li><a href="#res.attachment">res.attachment()</a>
</li>
<li><a href="#res.sendfile">res.sendfile()</a>
</li>
<li><a href="#res.download">res.download()</a>
</li>
<li><a href="#res.links">res.links()</a>
</li>
<li><a href="#res.locals">res.locals</a>
</li>
<li><a href="#res.render">res.render()</a>
</li>
</ul>
</li>
<li id="middleware-api"><a href="#middleware">Middleware</a>
<ul id="middleware-menu">
<li><a href="#basicAuth">basicAuth()</a>
</li>
<li><a href="#bodyParser">bodyParser()</a>
</li>
<li><a href="#compress">compress()</a>
</li>
<li><a href="#cookieParser">cookieParser()</a>
</li>
<li><a href="#cookieSession">cookieSession()</a>
</li>
<li><a href="#csrf">csrf()</a>
</li>
<li><a href="#directory">directory()</a>
</li>
</ul>
</li>
</ul>

View File

@@ -1,29 +0,0 @@
<h2 id="middleware">Middleware</h2>
<section markdown="1">
{% include api/en/3x/mw-basicAuth.md %}
</section>
<section markdown="1">
{% include api/en/3x/mw-bodyParser.md %}
</section>
<section markdown="1">
{% include api/en/3x/mw-compress.md %}
</section>
<section markdown="1">
{% include api/en/3x/mw-cookieParser.md %}
</section>
<section markdown="1">
{% include api/en/3x/mw-cookieSession.md %}
</section>
<section markdown="1">
{% include api/en/3x/mw-csrf.md %}
</section>
<section markdown="1">
{% include api/en/3x/mw-directory.md %}
</section>

View File

@@ -1,27 +0,0 @@
<h3 id='basicAuth'>basicAuth()</h3>
Basic Authentication middleware, populating `req.user`
with the username.
Simple username and password:
```js
app.use(express.basicAuth('username', 'password'))
```
Callback verification:
```js
app.use(express.basicAuth(function (user, pass) {
return user === 'tj' && pass === 'wahoo'
}))
```
Async callback verification, accepting `fn(err, user)`,
in this case `req.user` will be the user object passed.
```js
app.use(express.basicAuth(function (user, pass, fn) {
User.authenticate({ user: user, pass: pass }, fn)
}))
```

View File

@@ -1,27 +0,0 @@
<h3 id='bodyParser'>bodyParser()</h3>
Request body parsing middleware supporting JSON, urlencoded,
and multipart requests. This middleware is simply a wrapper
for the `json()`, `urlencoded()`, and
`multipart()` middleware.
```js
app.use(express.bodyParser())
// is equivalent to:
app.use(express.json())
app.use(express.urlencoded())
app.use(express.multipart())
```
For security sake, it's better to disable file upload if your application
doesn't need it. To do this, use only the needed middleware, i.e. don't use
the `bodyParser` and `multipart()` middleware:
```js
app.use(express.json())
app.use(express.urlencoded())
```
If your application needs file upload you should set up
<a href='https://groups.google.com/d/msg/express-js/iP2VyhkypHo/5AXQiYN3RPcJ'>a strategy for dealing with those files</a>.

View File

@@ -1,12 +0,0 @@
<h3 id='compress'>compress()</h3>
Compress response data with gzip / deflate. This middleware
should be placed "high" within the stack to ensure all
responses may be compressed.
```js
app.use(express.logger())
app.use(express.compress())
app.use(express.methodOverride())
app.use(express.bodyParser())
```

View File

@@ -1,10 +0,0 @@
<h3 id='cookieParser'>cookieParser()</h3>
Parses the Cookie header field and populates `req.cookies`
with an object keyed by the cookie names. Optionally you may enabled
signed cookie support by passing a `secret` string.
```js
app.use(express.cookieParser())
app.use(express.cookieParser('some secret'))
```

View File

@@ -1,19 +0,0 @@
<h3 id='cookieSession'>cookieSession()</h3>
Provides cookie-based sessions, and populates `req.session`.
This middleware takes the following options:
* `key` cookie name defaulting to `connect.sess`
* `secret` prevents cookie tampering
* `cookie` session cookie settings, defaulting to `{ path: '/', httpOnly: true, maxAge: null }`
* `proxy` trust the reverse proxy when setting secure cookies (via "x-forwarded-proto")
```js
app.use(express.cookieSession())
```
To clear a cookie simply assign the session to null before responding:
```js
req.session = null
```

View File

@@ -1,15 +0,0 @@
<h3 id='csrf'>csrf()</h3>
CSRF protection middleware.
By default this middleware generates a token named "_csrf"
which should be added to requests which mutate
state, within a hidden form field, query-string etc. This
token is validated against `req.csrfToken()`.
The default `value` function checks `req.body` generated
by the `bodyParser()` middleware, `req.query` generated
by `query()`, and the "X-CSRF-Token" header field.
This middleware requires session support, thus should be added
somewhere below `session()`.

View File

@@ -1,16 +0,0 @@
<h3 id='directory'>directory()</h3>
Directory serving middleware, serves the given `path`.
This middleware may be paired with `static()` to serve
files, providing a full-featured file browser.
```js
app.use(express.directory('public'))
app.use(express.static('public'))
```
This middleware accepts the following options:
* `hidden` display hidden (dot) files. Defaults to false.
* `icons` display icons. Defaults to false.
* `filter` Apply this filter function to files. Defaults to false.

View File

@@ -1,14 +0,0 @@
<h3 id='req.accepted'>req.accepted</h3>
Return an array of Accepted media types ordered from highest quality to lowest.
```
[ { value: 'application/json',
quality: 1,
type: 'application',
subtype: 'json' },
{ value: 'text/html',
quality: 0.5,
type: 'text',
subtype: 'html' } ]
```

View File

@@ -1,8 +0,0 @@
<h3 id='req.acceptedCharsets'>req.acceptedCharsets</h3>
Return an array of Accepted charsets ordered from highest quality to lowest.
```
Accept-Charset: iso-8859-5;q=.2, unicode-1-1;q=0.8
// => ['unicode-1-1', 'iso-8859-5']
```

View File

@@ -1,8 +0,0 @@
<h3 id='req.acceptedLanguages'>req.acceptedLanguages</h3>
Return an array of Accepted languages ordered from highest quality to lowest.
```
Accept-Language: en;q=.5, en-us
// => ['en-us', 'en']
```

View File

@@ -1,36 +0,0 @@
<h3 id='req.accepts'>req.accepts(types)</h3>
Check if the given `types` are acceptable, returning
the best match when true, otherwise `undefined` - in which
case you should respond with 406 "Not Acceptable".
The `type` value may be a single mime type string
such as "application/json", the extension name
such as "json", a comma-delimited list or an array. When a list
or array is given the best match, if any is returned.
```js
// Accept: text/html
req.accepts('html')
// => "html"
// Accept: text/*, application/json
req.accepts('html')
// => "html"
req.accepts('text/html')
// => "text/html"
req.accepts('json, text')
// => "json"
req.accepts('application/json')
// => "application/json"
// Accept: text/*, application/json
req.accepts('image/png')
req.accepts('png')
// => undefined
// Accept: text/*;q=.5, application/json
req.accepts(['html', 'json'])
req.accepts('html, json')
// => "json"
```

View File

@@ -1,3 +0,0 @@
<h3 id='req.acceptsCharset'>req.acceptsCharset(charset)</h3>
Check if the given `charset` are acceptable.

View File

@@ -1,3 +0,0 @@
<h3 id='req.acceptsLanguage'>req.acceptsLanguage(lang)</h3>
Check if the given `lang` are acceptable.

View File

@@ -1,19 +0,0 @@
<h3 id='req.body'>req.body</h3>
This property is an object containing the parsed request body. This feature
is provided by the `bodyParser()` middleware, though other body
parsing middleware may follow this convention as well. This property
defaults to `{}` when `bodyParser()` is used.
```js
// POST user[name]=tobi&user[email]=tobi@learnboost.com
console.log(req.body.user.name)
// => "tobi"
console.log(req.body.user.email)
// => "tobi@learnboost.com"
// POST { "name": "tobi" }
console.log(req.body.name)
// => "tobi"
```

View File

@@ -1,11 +0,0 @@
<h3 id='req.cookies'>req.cookies</h3>
This object requires the `cookieParser()` middleware for use.
It contains cookies sent by the user-agent. If no cookies are sent, it
defaults to `{}`.
```js
// Cookie: name=tj
console.log(req.cookies.name)
// => "tj"
```

View File

@@ -1,45 +0,0 @@
<h3 id='req.files'>req.files</h3>
This property is an object of the files uploaded. This feature
is provided by the `bodyParser()` middleware, though other body
parsing middleware may follow this convention as well. This property
defaults to `{}` when `bodyParser()` is used.
For example if a <strong>file</strong> field was named "image",
and a file was uploaded, `req.files.image` would contain
the following `File` object:
```
{ size: 74643,
path: '/tmp/8ef9c52abe857867fd0a4e9a819d1876',
name: 'edge.png',
type: 'image/png',
hash: false,
lastModifiedDate: Thu Aug 09 2012 20:07:51 GMT-0700 (PDT),
_writeStream:
{ path: '/tmp/8ef9c52abe857867fd0a4e9a819d1876',
fd: 13,
writable: false,
flags: 'w',
encoding: 'binary',
mode: 438,
bytesWritten: 74643,
busy: false,
_queue: [],
_open: [Function],
drainable: true },
length: [Getter],
filename: [Getter],
mime: [Getter] }
```
The `bodyParser()` middleware utilizes the
<a href="https://github.com/felixge/node-formidable">node-formidable</a>
module internally, and accepts the same options. An example of this
is the `keepExtensions` formidable option, defaulting to <strong>false</strong>
which in this case gives you the filename "/tmp/8ef9c52abe857867fd0a4e9a819d1876" void of
the ".png" extension. To enable this, and others you may pass them to `bodyParser()`:
```js
app.use(express.bodyParser({ keepExtensions: true, uploadDir: '/my/files' }))
```

View File

@@ -1,9 +0,0 @@
<h3 id='req.fresh'>req.fresh</h3>
Check if the request is fresh - aka Last-Modified and/or the ETag still match,
indicating that the resource is "fresh".
```js
console.dir(req.fresh)
// => true
```

View File

@@ -1,16 +0,0 @@
<h3 id='req.get'>req.get(field)</h3>
Get the case-insensitive request header `field`. The "Referrer" and "Referer" fields are interchangeable.
```js
req.get('Content-Type')
// => "text/plain"
req.get('content-type')
// => "text/plain"
req.get('Something')
// => undefined
```
p Aliased as `req.header(field)`.

View File

@@ -1,9 +0,0 @@
<h3 id='req.host'>req.host</h3>
Returns the hostname from the "Host" header field (void of portno).
```js
// Host: "example.com:3000"
console.dir(req.host)
// => 'example.com'
```

View File

@@ -1,9 +0,0 @@
<h3 id='req.ip'>req.ip</h3>
Return the remote address, or when "trust proxy"
is enabled - the upstream address.
```js
console.dir(req.ip)
// => '127.0.0.1'
```

View File

@@ -1,10 +0,0 @@
<h3 id='req.ips'>req.ips</h3>
When "trust proxy" is `true`, parse
the "X-Forwarded-For" ip address list
and return an array, otherwise an empty
array is returned.
For example if the value were "client, proxy1, proxy2"
you would receive the array `["client", "proxy1", "proxy2"]`
where "proxy2" is the furthest down-stream.

View File

@@ -1,21 +0,0 @@
<h3 id='req.is'>req.is(type)</h3>
Check if the incoming request contains the "Content-Type"
header field, and it matches the give mime `type`.
```js
// With Content-Type: text/html; charset=utf-8
req.is('html')
req.is('text/html')
req.is('text/*')
// => true
// When Content-Type is application/json
req.is('json')
req.is('application/json')
req.is('application/*')
// => true
req.is('html')
// => false
```

View File

@@ -1,13 +0,0 @@
<h3 id='req.originalUrl'>req.originalUrl</h3>
This property is much like `req.url`, however it retains
the original request url, allowing you to rewrite `req.url`
freely for internal routing purposes. For example the "mounting" feature
of <a href="#app.use">app.use()</a> will rewrite `req.url` to
strip the mount point.
```js
// GET /search?q=something
console.log(req.originalUrl)
// => "/search?q=something"
```

View File

@@ -1,27 +0,0 @@
<h3 id='req.param'>req.param(name)</h3>
Return the value of param `name` when present.
```js
// ?name=tobi
req.param('name')
// => "tobi"
// POST name=tobi
req.param('name')
// => "tobi"
// /user/tobi for /user/:name
req.param('name')
// => "tobi"
```
Lookup is performed in the following order:
* `req.params`
* `req.body`
* `req.query`
Direct access to `req.body`, `req.params`,
and `req.query` should be favoured for clarity - unless
you truly accept input from each object.

View File

@@ -1,22 +0,0 @@
<h3 id='req.params'>req.params</h3>
This property is an array containing properties mapped to the named route "parameters".
For example if you have the route `/user/:name`, then the "name" property
is available to you as `req.params.name`. This object defaults to `{}`.
```js
// GET /user/tj
console.dir(req.params.name)
// => 'tj'
```
When a regular expression is used for the route definition, capture groups
are provided in the array using `req.params[N]`, where `N`
is the nth capture group. This rule is applied to unnamed wild-card matches
with string routes such as `/file/*`:
```js
// GET /file/javascripts/jquery.js
console.dir(req.params[0])
// => 'javascripts/jquery.js'
```

View File

@@ -1,9 +0,0 @@
<h3 id='req.path'>req.path</h3>
Returns the request URL pathname.
```js
// example.com/users?sort=desc
console.dir(req.path)
// => '/users'
```

View File

@@ -1,13 +0,0 @@
<h3 id='req.protocol'>req.protocol</h3>
Return the protocol string "http" or "https"
when requested with TLS. When the "trust proxy"
setting is enabled the "X-Forwarded-Proto" header
field will be trusted. If you're running behind
a reverse proxy that supplies https for you this
may be enabled.
```js
console.dir(req.protocol)
// => 'http'
```

View File

@@ -1,20 +0,0 @@
<h3 id='req.query'>req.query</h3>
This property is an object containing the parsed query-string,
defaulting to `{}`.
```js
// GET /search?q=tobi+ferret
console.dir(req.query.q)
// => 'tobi ferret'
// GET /shoes?order=desc&shoe[color]=blue&shoe[type]=converse
console.dir(req.query.order)
// => 'desc'
console.dir(req.query.shoe.color)
// => 'blue'
console.dir(req.query.shoe.type)
// => 'converse'
```

View File

@@ -1,4 +0,0 @@
<h3 id='req.res'>req.res</h3>
This property holds a reference to the <a href="#response">response object</a>
that relates to this request object.

View File

@@ -1,22 +0,0 @@
<h3 id='req.route'>req.route</h3>
The currently matched `Route` containing
several properties such as the route's original path
string, the regexp generated, and so on.
```js
app.get('/user/:id?', function (req, res) {
console.dir(req.route)
})
```
Example output from the previous snippet:
```
{ path: '/user/:id?',
method: 'get',
callbacks: [ [Function] ],
keys: [ { name: 'id', optional: true } ],
regexp: /^\/user(?:\/([^\/]+?))?\/?$/i,
params: [ id: '12' ] }
```

View File

@@ -1,8 +0,0 @@
<h3 id='req.secure'>req.secure</h3>
Check if a TLS connection is established. This is a short-hand for:
```js
console.dir(req.protocol === 'https')
// => true
```

View File

@@ -1,15 +0,0 @@
<h3 id='req.signedCookies'>req.signedCookies</h3>
This object requires the `cookieParser(secret)` middleware for use.
It contains signed cookies sent by the user-agent, unsigned and ready for use.
Signed cookies reside in a different object to show developer intent; otherwise,
a malicious attack could be placed on `req.cookie` values (which are easy to spoof).
Note that signing a cookie does not make it "hidden" or encrypted; this simply
prevents tampering (because the secret used to sign is private). If no signed
cookies are sent, it defaults to `{}`.
```js
// Cookie: user=tobi.CP7AWaXDfAKIRfH49dQzKJx7sKzzSoPq7/AcBBRVwlI3
console.dir(req.signedCookies.user)
// => 'tobi'
```

View File

@@ -1,9 +0,0 @@
<h3 id='req.stale'>req.stale</h3>
Check if the request is stale - aka Last-Modified and/or the ETag do not match,
indicating that the resource is "stale".
```js
console.dir(req.stale)
// => true
```

View File

@@ -1,9 +0,0 @@
<h3 id='req.subdomains'>req.subdomains</h3>
Return subdomains as an array.
```js
// Host: "tobi.ferrets.example.com"
console.dir(req.subdomains)
// => ['ferrets', 'tobi']
```

View File

@@ -1,9 +0,0 @@
<h3 id='req.xhr'>req.xhr</h3>
Check if the request was issued with the "X-Requested-With"
header field set to "XMLHttpRequest" (jQuery etc).
```js
console.dir(req.xhr)
// => true
```

View File

@@ -1,116 +0,0 @@
<h2 id="request">Request</h2>
The `req` object is an enhanced version of Node's own request object
and supports all [built-in fields and methods](https://nodejs.org/api/http.html#http_class_http_incomingmessage).
<section markdown="1">
{% include api/en/3x/req-params.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-query.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-body.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-files.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-param.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-route.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-cookies.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-signedCookies.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-header.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-accepts.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-accepted.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-is.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-ip.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-ips.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-path.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-host.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-fresh.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-stale.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-xhr.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-protocol.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-secure.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-subdomains.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-originalUrl.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-acceptedLanguages.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-acceptedCharsets.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-acceptsCharset.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-acceptsLanguage.md %}
</section>
<section markdown="1">
{% include api/en/3x/req-res.md %}
</section>

View File

@@ -1,15 +0,0 @@
<h3 id='res.attachment'>res.attachment([filename])</h3>
Sets the Content-Disposition header field to "attachment". If
a `filename` is given then the Content-Type will be
automatically set based on the extname via `res.type()`,
and the Content-Disposition's "filename=" parameter will be set.
```js
res.attachment()
// Content-Disposition: attachment
res.attachment('path/to/logo.png')
// Content-Disposition: attachment; filename="logo.png"
// Content-Type: image/png
```

View File

@@ -1,9 +0,0 @@
<h3 id='res.charset'>res.charset</h3>
Assign the charset. Defaults to "utf-8".
```js
res.charset = 'value'
res.send('<p>some html</p>')
// => Content-Type: text/html; charset=value
```

View File

@@ -1,8 +0,0 @@
<h3 id='res.clearCookie'>res.clearCookie(name, [options])</h3>
Clear cookie `name`. The `path` option defaults to "/".
```js
res.cookie('name', 'tobi', { path: '/admin' })
res.clearCookie('name', { path: '/admin' })
```

View File

@@ -1,37 +0,0 @@
<h3 id='res.cookie'>res.cookie(name, value, [options])</h3>
Set cookie `name` to `value`, which may be a string or object converted to JSON. The `path`
option defaults to "/".
```js
res.cookie('name', 'tobi', { domain: '.example.com', path: '/admin', secure: true })
res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true })
```
The `maxAge` option is a convenience option for setting "expires"
relative to the current time in milliseconds. The following is equivalent to
the previous example.
```js
res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
```
An object may be passed which is then serialized as JSON, which is
automatically parsed by the `bodyParser()` middleware.
```js
res.cookie('cart', { items: [1, 2, 3] })
res.cookie('cart', { items: [1, 2, 3] }, { maxAge: 900000 })
```
Signed cookies are also supported through this method. Simply
pass the `signed` option. When given `res.cookie()`
will use the secret passed to `express.cookieParser(secret)`
to sign the value.
```js
res.cookie('name', 'tobi', { signed: true })
```
Later you may access this value through the <a href="#req.signedCookies">req.signedCookie</a>
object.

View File

@@ -1,26 +0,0 @@
<h3 id='res.download'>res.download(path, [filename], [fn])</h3>
Transfer the file at `path` as an "attachment",
typically browsers will prompt the user for download. The
Content-Disposition "filename=" parameter, aka the one
that will appear in the brower dialog is set to `path`
by default, however you may provide an override `filename`.
When an error has ocurred or transfer is complete the optional
callback `fn` is invoked. This method uses <a href="#res.sendfile">res.sendfile()</a>
to transfer the file.
```js
res.download('/report-12345.pdf')
res.download('/report-12345.pdf', 'report.pdf')
res.download('/report-12345.pdf', 'report.pdf', function (err) {
if (err) {
// handle error, keep in mind the response may be partially-sent
// so check res.headerSent
} else {
// decrement a download credit etc
}
})
```

View File

@@ -1,52 +0,0 @@
<h3 id='res.format'>res.format(object)</h3>
Performs content-negotiation on the request Accept header
field when present. This method uses `req.accepted`, an array of
acceptable types ordered by their quality values, otherwise the
first callback is invoked. When no match is performed the server
responds with 406 "Not Acceptable", or invokes the `default`
callback.
The Content-Type is set for you when a callback is selected,
however you may alter this within the callback using `res.set()`
or `res.type()` etcetera.
The following example would respond with `{ "message": "hey" }`
when the Accept header field is set to "application/json" or "*/json",
however if "*/*" is given then "hey" will be the response.
```js
res.format({
'text/plain': function () {
res.send('hey')
},
'text/html': function () {
res.send('<p>hey</p>')
},
'application/json': function () {
res.send({ message: 'hey' })
}
})
```
In addition to canonicalized MIME types you may also
use extnames mapped to these types, providing a slightly
less verbose implementation:
```js
res.format({
text: function () {
res.send('hey')
},
html: function () {
res.send('<p>hey</p>')
},
json: function () {
res.send({ message: 'hey' })
}
})
```

View File

@@ -1,8 +0,0 @@
<h3 id='res.get'>res.get(field)</h3>
Get the case-insensitive response header `field`.
```js
res.get('Content-Type')
// => "text/plain"
```

Some files were not shown because too many files have changed in this diff Show More