nodemon.json


Overview

The `nodemon.json` file is a configuration file for **Nodemon**, a utility that monitors for any changes in your source files and automatically restarts your Node.js application. This file defines specific options to control which files Nodemon will watch or ignore, the file extensions to monitor, and the command to execute when changes are detected.

In this project, `nodemon.json` is tailored to a TypeScript-based Node.js application that uses a build step before starting the server. It ensures that the development environment efficiently rebuilds and restarts the application whenever relevant source files or build artifacts change, improving the developer experience and productivity.


Configuration Properties

The file contains a JSON object with the following properties:

Property

Type

Description

`ignore`

Array of Strings

Specifies file paths or patterns that Nodemon should **ignore** when watching for changes. Changes to these files will **not** trigger a restart.

`watch`

Array of Strings

Lists files or directories Nodemon should **watch** for changes, in addition to the default watch behavior. When changes occur in these paths, Nodemon triggers a restart.

`ext`

String

A comma-separated list of file extensions (without the dot) that Nodemon should watch for changes. In this file, it's `"ts"`, meaning Nodemon watches TypeScript files.

`exec`

String

The shell command Nodemon runs when restarting the application. Here, it first runs a build command and then starts the compiled JavaScript application.


Detailed Explanation

Properties and Their Usage

{
  "ignore": ["src/routes.ts"],
  "watch": [
    "../../../packages/*/dist/tsconfig.tsbuildinfo",
    "../../common/api/dist/tsconfig.tsbuildinfo",
    "src"
  ],
  "ext": "ts",
  "exec": "yarn build && node dist/optimism/api/src/app.js"
}

Usage Example

Assuming you have Nodemon installed globally or as a development dependency, starting Nodemon with this configuration is as simple as:

nodemon

Nodemon automatically reads `nodemon.json` in the current directory and applies the defined configuration. It watches `.ts` files in the `src` folder and the specified build info files, ignoring changes in `src/routes.ts`. When a relevant change is detected, it runs the build command and restarts the app.


Implementation Details and Considerations


Interaction with Other Parts of the System


Visual Diagram

The following flowchart illustrates the workflow of Nodemon with this configuration file:

flowchart TD
    A[File Change Detected] --> B{Is file ignored?}
    B -- Yes --> C[No Restart]
    B -- No --> D{Is file extension "ts"?}
    D -- No --> C
    D -- Yes --> E{Is file in watch list or src?}
    E -- No --> C
    E -- Yes --> F[Trigger Restart]
    F --> G[Run "yarn build"]
    G --> H[Build Completes]
    H --> I[Run "node dist/optimism/api/src/app.js"]
    I --> J[App Running with Updated Code]

Summary

This configuration file plays a crucial role in the development workflow by automating rebuilds and restarts, thus improving productivity and ensuring the running application reflects the latest changes.