Debian Codegraph @

guide/src/cli/serve.md

raw
1 # The serve command
2
3 The serve command is used to preview a book by serving it via HTTP at
4 `localhost:3000` by default:
5
6 ```bash
7 mdbook serve
8 ```
9
10 The `serve` command watches the book's `src` directory for
11 changes, rebuilding the book and refreshing clients for each change; this includes
12 re-creating deleted files still mentioned in `SUMMARY.md`! A websocket
13 connection is used to trigger the client-side refresh.
14
15 ***Note:*** *The `serve` command is for testing a book's HTML output, and is not
16 intended to be a complete HTTP server for a website.*
17
18 #### Specify a directory
19
20 The `serve` command can take a directory as an argument to use as the book's
21 root instead of the current working directory.
22
23 ```bash
24 mdbook serve path/to/book
25 ```
26
27 ### Server options
28
29 The `serve` hostname defaults to `localhost`, and the port defaults to `3000`. Either option can be specified on the command line:
30
31 ```bash
32 mdbook serve path/to/book -p 8000 -n 127.0.0.1
33 ```
34
35 #### `--open`
36
37 When you use the `--open` (`-o`) flag, mdbook will open the book in your
38 default web browser after starting the server.
39
40 #### `--dest-dir`
41
42 The `--dest-dir` (`-d`) option allows you to change the output directory for the
43 book. Relative paths are interpreted relative to the current directory. If
44 not specified it will default to the value of the `build.build-dir` key in
45 `book.toml`, or to `./book`.
46
47 {{#include arg-watcher.md}}
48
49 #### Specify exclude patterns
50
51 The `serve` command will not automatically trigger a build for files listed in
52 the `.gitignore` file in the book root directory. The `.gitignore` file may
53 contain file patterns described in the [gitignore
54 documentation](https://git-scm.com/docs/gitignore). This can be useful for
55 ignoring temporary files created by some editors.
56
57 ***Note:*** *Only the `.gitignore` from the book root directory is used. Global
58 `$HOME/.gitignore` or `.gitignore` files in parent directories are not used.*