Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
108 changes: 103 additions & 5 deletions src/content/docs/de/4x/guide/debugging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: Erfahren Sie, wie Sie Debugging-Logs in Express.js-Anwendungen akti
---

import Alert from '@components/primitives/Alert/Alert.astro';
import PackageManagerCommand from '@components/patterns/PackageManagerCommand/PackageManagerCommand.astro';

Um alle internen Logs zu sehen, die in Express verwendet werden, setzen Sie die Umgebungsvariable `DEBUG` auf
`express:*` beim Starten Ihrer App.
Expand Down Expand Up @@ -86,22 +87,119 @@ Wenn eine Anfrage an die App gestellt wird, sehen Sie die im Express-Code angege

Um die Protokolle nur von der Router-Implementierung zu sehen, setzen Sie den Wert `DEBUG` auf `express:router`. Um Protokolle nur von der Anwendungsimplementierung zu sehen, setzten Sie den Wert von `DEBUG` auf `express:application`, und so weiter.

## Anwendungen generiert von `Express`
## Using `debug` in your own code

Eine Anwendung, die durch den Befehl `express generiert` erzeugt wird, benutzt das Modul `debug` und sein Debug-Namensraum wird auf den Namen der Anwendung übertragen.
The same [debug](https://www.npmjs.com/package/debug) module that Express uses internally is available for your application code. Install it, create one or more loggers scoped to a namespace of your choosing, and call them wherever you would otherwise use `console.log`:

Wenn Sie zum Beispiel die App mit `$ express Beispiel-App` erstellt haben, können Sie die Debug-Anweisungen mit folgendem Befehl aktivieren:
<PackageManagerCommand command="npm install debug" />

```cjs title="index.cjs"
const express = require('express');
const debug = require('debug')('myapp:server');

const app = express();

app.get('/', (req, res) => {
debug('handling request from %s', req.ip);
res.send('Hello World!');
});

app.listen(3000, () => {
debug('listening on port 3000');
});
```

```mjs title="index.mjs"
import express from 'express';
import debugModule from 'debug';

const debug = debugModule('myapp:server');
const app = express();

app.get('/', (req, res) => {
debug('handling request from %s', req.ip);
res.send('Hello World!');
});

app.listen(3000, () => {
debug('listening on port 3000');
});
```

These statements print nothing by default. Enable them through the same `DEBUG` environment variable, using your own namespace:

```bash
$ DEBUG=sample-app:* node ./bin/www
$ DEBUG=myapp:* node index.js
```

Sie können mehr als einen Debug-Namensraum angeben, indem Sie eine kommaseparierte Namensliste zuweisen:

```bash
$ DEBUG=http,mail,express:* node index.js
$ DEBUG=myapp:*,express:router node index.js
```

## Setting DEBUG in your IDE

The `DEBUG` environment variable can be set by any process launcher that supports environment variables, including the run and debug configurations of your IDE. For example, in VS Code you can set it in the `env` property of a launch configuration:

```json title=".vscode/launch.json"
{
"type": "node",
"request": "launch",
"name": "Launch Express app",
"program": "${workspaceFolder}/index.js",
"env": { "DEBUG": "express:*" }
}
```

See [Node.js debugging in VS Code](https://code.visualstudio.com/docs/nodejs/nodejs-debugging) for the full list of launch options.

## Using the Node.js inspector

Debug logs show what the app did; for stepping through your code with breakpoints, use the built-in Node.js inspector. Start your app with the `--inspect` flag:

```bash
$ node --inspect index.js
```

Then attach a debugging client, such as Chrome DevTools (open `chrome://inspect`), VS Code, or any other inspector-capable tool, to set breakpoints in your route handlers and middleware, step through code, and inspect variables.

If you need to debug something that happens during startup, use `--inspect-brk` instead, which pauses execution on the first line until a debugger attaches. See the [Node.js debugging guide](https://nodejs.org/learn/getting-started/debugging) for details.

## Debugging the HTTP layer

Express runs on top of the Node.js `http` module, which has its own debugging facilities that work with any Express app.

Setting the `NODE_DEBUG` environment variable to `http` makes Node.js print internal logs from the HTTP layer, such as connection handling and socket events:

```bash
$ NODE_DEBUG=http node index.js
```

You can combine it with other subsystems, such as `net` or `stream`, in a comma-separated list. Be aware that this output can expose sensitive data such as authentication headers, so use it only in development.

## Diagnostics channels

Node.js publishes an event for every HTTP request through the [diagnostics_channel](https://nodejs.org/api/diagnostics_channel.html#http) module, which you can subscribe to without patching Express or adding middleware:

```cjs title="index.cjs"
const { subscribe } = require('node:diagnostics_channel');

subscribe('http.server.request.start', ({ request }) => {
console.log(`${request.method} ${request.url}`);
});
```

```mjs title="index.mjs"
import { subscribe } from 'node:diagnostics_channel';

subscribe('http.server.request.start', ({ request }) => {
console.log(`${request.method} ${request.url}`);
});
```

Other built-in channels cover the rest of the request lifecycle, such as `http.server.response.finish`, and the client side of `http.request` calls. See the [diagnostics_channel documentation](https://nodejs.org/api/diagnostics_channel.html#http) for the full list.

## Erweiterte Optionen

Wenn Sie über Node.js laufen, können Sie ein paar Umgebungsvariablen festlegen, die das Verhalten der Debug-Protokollierung ändern:
Expand Down
40 changes: 24 additions & 16 deletions src/content/docs/de/4x/guide/error-handling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,39 @@ app.get('/', (req: Request, res: Response, next: NextFunction) => {
});
```

Starting with Express 5, route handlers and middleware that return a Promise
will call `next(value)` automatically when they reject or throw an error.
Zum Beispiel:
Errors from rejected promises are not passed to `next` automatically, and this includes `async` functions: if an `async` route handler throws or awaits a rejected promise, the rejection is unhandled, which crashes the process on current Node.js versions. You must catch the error yourself and pass it to Express:

```js
app.get('/user/:id', async (req, res, next) => {
const user = await getUserById(req.params.id);
res.send(user);
try {
const user = await getUserById(req.params.id);
res.send(user);
} catch (err) {
next(err);
}
});
```

```ts
import { type Request, type Response, type NextFunction } from 'express';

app.get('/user/:id', async (req: Request, res: Response, next: NextFunction) => {
const user = await getUserById(req.params.id);
res.send(user);
try {
const user = await getUserById(req.params.id);
res.send(user);
} catch (err) {
next(err);
}
});
```

Wenn `getUserById` einen Fehler oder eine Ablehnung, wird `next` entweder mit
dem Wurffehler oder dem abgelehnten Wert aufgerufen. Wenn kein abgelehnter Wert angegeben wird, wird `next`
mit einem Standard-Fehlerobjekt aufgerufen, das vom Express-Router bereitgestellt wird.
<Alert type="info">

Consider [updating to Express 5](/guide/migrating-5), where route handlers and middleware that
return a Promise call `next(value)` automatically when they reject or throw an error, making the
`try...catch` above unnecessary.

</Alert>

Wenn du etwas an die `next()` Funktion übergibt (außer den String `'route'`),
Express betrachtet die aktuelle Anfrage als Fehler und überspringt alle
Expand Down Expand Up @@ -180,9 +190,7 @@ app.get('/', (req: Request, res: Response, next: NextFunction) => {
});
```

Da Versprechungen automatisch sowohl synchrone Fehler als auch abgelehnte Versprechungen fangen,
du kannst einfach `next` angeben, da der letzte Catch Handler und Express Fehler fängt an
weil der Catch-Handler den Fehler als erstes Argument angibt.
If a callback in the promise chain throws, the chain turns that exception into a rejection, which travels down to the final `.catch`. There, passing `next` as the handler is enough: `.catch` calls it with the error as its first argument, which is exactly the argument `next` expects, so the error reaches Express.

Sie können auch eine Kette von Handlern verwenden, um sich auf synchrone Fehler
zu stützen, indem Sie den asynchronen Code auf etwas Triviales reduzieren. Zum Beispiel:
Expand Down Expand Up @@ -219,8 +227,8 @@ app.get('/', [
]);
```

Das obige Beispiel hat ein paar triviale Anweisungen aus dem Aufruf `readFile`
. If `readFile` causes an error, then it passes the error to Express, otherwise you
The above example contains a couple of trivial statements following the `readFile`
call. If `readFile` causes an error, then it passes the error to Express, otherwise you
quickly return to the world of synchronous error handling in the next handler
in the chain. Dann versucht das obige Beispiel die Daten zu verarbeiten. Wenn dies fehlschlägt, fängt der Synchron-Fehlerhandler
ihn ab. Hätten Sie diese Verarbeitung innerhalb von
Expand Down Expand Up @@ -424,7 +432,7 @@ function logErrors(err: Error, req: Request, res: Response, next: NextFunction)

Auch in diesem Beispiel wird `clientErrorHandler` wie folgt definiert; in diesem Fall wird der Fehler explizit an den nächsten weitergegeben.

Beachten Sie, dass, wenn _not_ in einer Fehlerbehandlungsfunktion "Weiter" aufruft, Sie dafür verantwortlich sind, die Antwort zu schreiben (und zu beenden). Andernfalls werden diese Anträge "hängen" und sind nicht für die Müllsammlung berechtigt.
Notice that when you do not call `next` in an error-handling function, you are responsible for writing (and ending) the response. Andernfalls werden diese Anträge "hängen" und sind nicht für die Müllsammlung berechtigt.

```js
function clientErrorHandler(err, req, res, next) {
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/de/4x/guide/overriding-express-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Discover how to customize and extend the Express.js API by overridi

import Alert from '@components/primitives/Alert/Alert.astro';

Die Express API besteht aus verschiedenen Methoden und Eigenschaften auf den Anfrage- und Antwort-Objekten. Diese werden vom Prototyp geerbt. Es gibt zwei Erweiterungspunkte für die Express API:
The Express API consists of various methods and properties on the [request](/api/request) and [response](/api/response) objects. Diese werden vom Prototyp geerbt. Es gibt zwei Erweiterungspunkte für die Express API:

1. Die globalen Prototypen unter `express.request` und `express.response`.
2. App-spezifische Prototypen bei `app.request` und `app.response`.
Expand Down
46 changes: 37 additions & 9 deletions src/content/docs/de/4x/guide/routing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ _Routing_ bezieht sich darauf, wie die Endpunkte einer Anwendung (URIs) auf Kund
Für eine Einführung in das Routing siehe [Basic routing](/starter/basic-routing).

Du definierst Routing, indem du Methoden des Express `app` Objekts verwendest, die den HTTP-Methoden entsprechen;
zum Beispiel, `app. et()` um GET-Anfragen und `app.post` zu behandeln, um POST-Anfragen zu bearbeiten. For a full list,
zum Beispiel, `app.get()` um GET-Anfragen und `app.post` zu behandeln, um POST-Anfragen zu bearbeiten. For a full list,
see [app.METHOD](/api/application#appmethod). You can also use [app.all()](/api/application#appall) to handle all HTTP methods and [app.use()](/api/application#appuse) to
specify middleware as the callback function (See [Using middleware](/guide/using-middleware) for details).

These routing methods specify a callback function (sometimes called a "handler function") that Express automatically runs when the application receives a request matching the specified route (endpoint) and HTTP method. Mit anderen Worten, die Anwendung "lauscht" für Anforderungen, die mit der angegebenen Route(s) und Methode(n) übereinstimmen und wenn es ein Spiel erkennt, ruft es die angegebene Callback-Funktion auf.
Mit anderen Worten, die Anwendung "lauscht" für Anforderungen, die mit der angegebenen Route(s) und Methode(n) übereinstimmen und wenn es ein Spiel erkennt, ruft es die angegebene Callback-Funktion auf. Mit anderen Worten, die Anwendung "lauscht" für Anforderungen, die mit der angegebenen Route(s) und Methode(n) übereinstimmen und wenn es ein Spiel erkennt, ruft es die angegebene Callback-Funktion auf.

In der Tat können die Routing-Methoden mehr als eine Callback-Funktion als Argumente haben.
Mit mehreren Callback-Funktionen, es ist wichtig, `next` als Argument für die Callback-Funktion zur Verfügung zu stellen und dann `next()` im Körper der Funktion aufzurufen, um die Steuerung
Expand Down Expand Up @@ -88,7 +88,7 @@ app.post('/', (req: Request, res: Response) => {
Express unterstützt Methoden, die allen HTTP-Anfragemethoden entsprechen: `get`, `post` und so weiter.
For a full list, see [app.METHOD](/api/application#appmethod).

Es gibt eine spezielle Routing-Methode, `app.all()`, die benutzt wird, um Middleware-Funktionen an einem Pfad für _all_ HTTP-Requestmethoden zu laden. For example, the following handler is executed for requests to the route `"/secret"` whether using `GET`, `QUERY`, `POST`, `PUT`, `DELETE`, or any other HTTP request method supported in the [http module](https://nodejs.org/api/http.html#http_http_methods).
Es gibt eine spezielle Routing-Methode, `app.all()`, die benutzt wird, um Middleware-Funktionen an einem Pfad für _all_ HTTP-Requestmethoden zu laden. For example, the following handler is executed for requests to the route `"/secret"` whether using `GET`, `QUERY`, `POST`, `PUT`, `DELETE`, or any other HTTP request method supported in the [http module](https://nodejs.org/api/http.html#httpmethods).

```js
app.all('/secret', (req, res, next) => {
Expand All @@ -108,7 +108,7 @@ app.all('/secret', (req: Request, res: Response, next: NextFunction) => {

## Routenpfade

Routenpfade in Kombination mit einer Anfragemethode definieren die Endpunkte, an denen Anfragen gestellt werden können. Routenpfade können Zeichenketten, Zeichenkettenmuster oder reguläre Ausdrücke sein.
Routenpfade in Kombination mit einer Anfragemethode definieren die Endpunkte, an denen Anfragen gestellt werden können. Routenpfade können Zeichenketten, Zeichenkettenmuster oder reguläre Ausdrücke sein. They can also capture values from the URL, as described in [Route parameters](#route-parameters) below.

<Alert type="info">

Expand Down Expand Up @@ -235,6 +235,26 @@ app.get('/ab(cd)?e', (req: Request, res: Response) => {
});
```

A wildcard (`*`) on its own matches anything at its position, including entire subpaths. For example, this route path will match `/file/style.css` as well as `/file/javascripts/jquery.js`. Wildcards are unnamed, so the matched value is available as `req.params[0]` instead of a named parameter.

```js
app.get('/file/*', (req, res) => {
// GET /file/javascripts/jquery.js
res.send(req.params[0]);
// => 'javascripts/jquery.js'
});
```

```ts
import { type Request, type Response } from 'express';

app.get('/file/*', (req: Request, res: Response) => {
// GET /file/javascripts/jquery.js
res.send(req.params[0]);
// => 'javascripts/jquery.js'
});
```

### Routenpfade basierend auf regulären Ausdrücken

<Alert type="warnung">
Expand Down Expand Up @@ -348,6 +368,14 @@ Zeichen mit einem zusätzlichen Backslash maskieren, zum Beispiel `\d+`.
The [`*`](https://github.com/expressjs/express/issues/2495) character in regular expressions is not interpreted in the usual way. Benutze `{0,}` anstelle von `*`.
</Alert>

Unlike named route parameters, wildcard (`*`) matches in [string patterns](#route-paths-based-on-string-patterns) and capture groups in regular expressions are unnamed: their values are available by position, as `req.params[0]`, `req.params[1]`, and so on.

```
Route path: /file/*/size/*
Request URL: http://localhost:3000/file/javascripts/jquery.js/size/large
req.params: { "0": "javascripts/jquery.js", "1": "large" }
```

## Routenhandler

Du kannst mehrere Callback-Funktionen bereitstellen, die sich wie [middleware](/guide/using-middleware) verhalten um eine Anfrage zu bearbeiten. Die einzige Ausnahme ist, dass diese Callbacks `next('route')` aufrufen könnten, um die restlichen Rufnummern zu umgehen. Sie können diesen Mechanismus nutzen, um Vorbedingungen auf einer Route aufzuerlegen, dann die Kontrolle an die nachfolgenden Routen übergeben, wenn es keinen Grund gibt, mit der aktuellen Route fortzufahren.
Expand Down Expand Up @@ -387,7 +415,7 @@ In diesem Beispiel:

Routenhandler können in Form einer Funktion, eines Arrays von Funktionen oder Kombinationen beider sein, wie in den folgenden Beispielen gezeigt.

Eine einzelne Callback-Funktion kann eine Route handhaben. Zum Beispiel:
Mehr als eine Callback-Funktion kann eine Route handhaben (stelle sicher, dass du das `next` Objekt angibst). Zum Beispiel:

```js
app.get('/example/a', (req, res) => {
Expand All @@ -403,7 +431,7 @@ app.get('/example/a', (req: Request, res: Response) => {
});
```

Mehr als eine Callback-Funktion kann eine Route handhaben (stelle sicher, dass du das `next` Objekt angibst). Zum Beispiel:
Eine Kombination aus unabhängigen Funktionen und Arrays von Funktionen kann eine Route handhaben. Zum Beispiel:

```js
app.get(
Expand Down Expand Up @@ -527,7 +555,7 @@ app.get(

## Antwortmethoden

Die Methoden auf dem Antwortobjekt (`res`) in der folgenden Tabelle können eine Antwort an den Client senden und den Request-Antwort-Zyklus beenden. Wenn keine dieser Methoden von einem Routenhandler aufgerufen wird, bleibt die Client-Anfrage hängen.
The methods on the [response object](/api/response) (`res`) in the following table can send a response to the client, and terminate the request-response cycle. Wenn keine dieser Methoden von einem Routenhandler aufgerufen wird, bleibt die Client-Anfrage hängen.

| Methode | Beschreibung |
| ----------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
Expand All @@ -544,7 +572,7 @@ Die Methoden auf dem Antwortobjekt (`res`) in der folgenden Tabelle können eine
## app.route()

Sie können verkettende Routenhandler für einen Routenpfad erstellen, indem Sie `app.route()` verwenden.
Da der Weg an einem einzigen Ort angegeben wird, ist die Schaffung modularer Routen hilfreich, ebenso wie die Reduzierung von Redundanz und Typos. Weitere Informationen über Routen finden Sie unter [Router() documentation](/api/router).
Because the path is specified in a single location, this helps to create modular routes and reduces redundancy and typos. For more information about routes, see the [Router() documentation](/api/router).

Hier ist ein Beispiel für verkettete Routenhandler, die mit `app.route()` definiert werden.

Expand Down Expand Up @@ -677,7 +705,7 @@ app.use('/birds', birds);

Die App wird nun in der Lage sein, Anfragen an `/birds` und `/birds/about` zu bearbeiten, aufrufen sowie die Middleware-Funktion `timeLog` aufrufen, die spezifisch für die Route ist.

Aber wenn die übergeordnete Route `/birds` Pfadparameter hat, wird sie standardmäßig nicht von den Unterrouten aus erreichbar sein. To make it accessible, you will need to pass the `mergeParams` option to the Router constructor [reference](/api/application#appuse).
Aber wenn die übergeordnete Route `/birds` Pfadparameter hat, wird sie standardmäßig nicht von den Unterrouten aus erreichbar sein. To make it accessible, you will need to pass the `mergeParams` option to the [Router constructor](/api/express/#expressrouter).

```js
const router = express.Router({ mergeParams: true });
Expand Down
Loading