> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Commands

UltraModern.js has some built-in commands that can help you quickly start a development server, build production environment code, and more.

Through this chapter, you can learn about the built-in commands of UltraModern.js and how to use them.

## modern dev

The `modern dev` command is used to start a local development server and compile the source code in the development environment.

```bash
Usage: modern dev [options]

Options:
  -e --entry <entry>    compiler by entry
  -c --config <config>  specify the configuration file, which can be a relative or absolute path
  -h, --help            show command help
  --web-only            only start web service
  --api-only            only start API service
```

After running `modern dev`, UltraModern.js will watch source file changes and apply hot module replacement.

```bash
$ modern dev

info    Starting dev server...

  > Local:    http://localhost:8080/
  > Network:  http://192.168.0.1:8080/
```

### Compile Partial Pages

In multi-page (MPA) projects, the `--entry` option can be added to specify one or more pages to compile. In this way, only part of the code in the project will be compiled, and the dev startup speed will be faster.

For example, execute `modern dev --entry`, the entry selector will be displayed in the command line interface:

```text
$ modern dev --entry

? Please select the entry that needs to be built
❯ ◯ foo
  ◯ bar
  ◯ baz
```

For example, if you select the `foo` entry, only the code related to the `foo` entry will be compiled, and the code of other pages will not be compiled.

### Specify the page by parameter

You can also specify the page name through parameters after `--entry`, and the names of multiple pages can be separated by commas.

```bash
# Compile foo page
modern dev --entry foo

# Compile foo and bar pages
modern dev --entry foo,bar
```

## modern start

`modern start` is an alias of `modern dev` command, the usage of the two are exactly the same.

## modern build

The `modern build` command will build production-ready artifacts in the `dist/` directory by default. You can specify the output directory by modifying the configuration [`output.distPath`](/configure/app/output/dist-path.md).

```bash
Usage: modern build [options]

Options:
  -c --config <config>  specify the configuration file, which can be a relative or absolute path
  -h, --help            show command help
  -w --watch            turn on watch mode, watch for changes and rebuild
```

## modern runtime status

The `modern runtime status` command reads the runtime status endpoint and prints the response. It targets `http://127.0.0.1:8080/_modern/runtime/status` by default.

```bash
Usage: modern runtime status [options]

Options:
  --endpoint <endpoint>  runtime status endpoint URL or path
  --token <token>        runtime status auth token
  --token-env <name>     environment variable name that stores runtime status auth token (default: "MODERN_RUNTIME_SIGNAL_TOKEN")
  --header-name <name>   auth header name (default: "x-modernjs-runtime-signal-token")
  --timeout <ms>         request timeout in milliseconds (default: "5000")
  --json                 output as JSON format for machine reading
  -h, --help             display help for command
```

If `--endpoint` is a path, it is resolved against `http://127.0.0.1:8080`. If `--token` is omitted, the command reads the token from the environment variable named by `--token-env`.

By default, the command formats the response as readable key/value lines. Add `--json` to print the raw JSON payload.

```bash
modern runtime status --json
```

## modern runtime fallback-signal

The `modern runtime fallback-signal` command posts a runtime fallback signal to the canary contract-gate endpoint. It targets `http://127.0.0.1:8080/_modern/contract-gates/runtime-fallback` by default.

```bash
Usage: modern runtime fallback-signal [options]

Options:
  --app <appName>          remote app name
  --endpoint <endpoint>    runtime fallback signal endpoint URL or path
  --reason <reason>        fallback reason (default: "runtime_fallback")
  --phase <phase>          fallback phase (default: "load")
  --entry <entry>          remote entry URL
  --runtime-digest <digest>  runtime digest value
  --metadata <json>        metadata JSON object string
  --token <token>          runtime signal auth token
  --token-env <name>       environment variable name that stores runtime signal auth token (default: "MODERN_RUNTIME_SIGNAL_TOKEN")
  --header-name <name>     auth header name (default: "x-modernjs-runtime-signal-token")
  --timeout <ms>           request timeout in milliseconds (default: "5000")
  --json                   output as JSON format for machine reading
  -h, --help               display help for command
```

The request body always includes `appName`, `reason`, and `phase`. It includes `entry`, `runtimeDigest`, and `metadata` only when those options are provided. `--metadata` must be a JSON object string.

```bash
modern runtime fallback-signal --app crm-shell --reason remote_load_failed --phase load --json
```

## modern serve

The `modern serve` command is used to start an UltraModern.js project in the production environment. It can also be used to preview the artifacts built for the production environment locally. Please note that you need to execute the [`build`](/apis/app/commands.md#modern-build) command beforehand to generate the corresponding artifacts.

```bash
Usage: modern serve [options]

Options:
  -c --config <config>  specify the configuration file, which can be a relative or absolute path
  -h, --help            show command help
  --api-only            only run API service
```

By default, the project will run in `localhost:8080`, you can modify the server port number with `server.port`:

```js
export default defineConfig({
  server: {
    port: 8081,
  },
});
```

## modern inspect

The `modern inspect` command is used to view the UltraModern.js config, [Rsbuild config](https://v2.rsbuild.rs/config/index) and Rspack config of the project.

```bash
Usage: modern inspect [options]

Options:
  --env <env>           view the configuration in the target environment (default: "development")
  --output <output>     Specify the path to output in the dist (default: "./")
  --verbose             Show the full function in the result
  -c --config <config>  specify the configuration file, which can be a relative or absolute path
  -h, --help            show command help
```

After executing the command `npx modern inspect` in the project root directory, the following files will be generated in the `dist` directory of the project:

- `modern.js.config.mjs`:The Modern.js configuration currently used.
- `rsbuild.config.mjs`: The Rsbuild config to use at build time.
- `rspack.config.web.mjs`: The Rspack config used by to use at build time.

```bash
➜ npx modern inspect

Inspect config succeed, open following files to view the content:

  - Rsbuild Config: /root/my-project/dist/rsbuild.config.mjs
  - Rspack Config (web): /root/my-project/dist/rspack.config.web.mjs
  - Modern.js Config: /root/my-project/dist/modern.js.config.mjs
```

### Configuration Env

By default, the inspect command will output the development configs, you can use the `--env production` option to output the production configs:

```bash
modern inspect --env production
```

### Verbose content

By default, the inspect command will omit the function content in the config object, you can use the `--verbose` option to output the full content of the function:

```bash
modern inspect --verbose
```

### SSR Configuration

If the project has enabled SSR, an additional `rspack.config.node.mjs` file will be generated in the `dist/`, corresponding to the Rspack configuration at SSR build time.

```bash
➜ npx modern inspect

Inspect config succeed, open following files to view the content:

  - Rsbuild Config: /root/my-project/dist/rsbuild.config.mjs
  - Rspack Config (web): /root/my-project/dist/rspack.config.web.mjs
  - Rspack Config (node): /root/my-project/dist/rspack.config.node.mjs
  - Modern.js Config: /root/my-project/dist/modern.js.config.mjs
```

## modern deploy

The `modern deploy` command is used to generate artifacts required for the deployment platform.

```bash
Usage: modern deploy [options]

Options:
  -c --config <config>  Specify configuration file path, either relative or absolute
  -s --skip-build       Skip the build stage
  -h, --help            Display command help
```

For more details, refer to [Deploy Application](/guides/basic-features/deploy.md).
