nodemon.json


Overview

The `nodemon.json` file is a configuration file used by **Nodemon**, a utility that monitors changes in source files and automatically restarts the Node.js application. This specific configuration customizes Nodemon's behavior to enhance the development workflow for a TypeScript-based project, particularly focusing on rebuilding the project before execution and selectively watching and ignoring certain files.

This file:


Configuration Properties

The file content is a JSON object with the following properties:

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

Property Details

Property

Type

Description

Example

`ignore`

Array of strings

Specifies files or directories that Nodemon should **ignore** and not watch for changes. This is useful to exclude files that change frequently but should not trigger a restart.

`["src/routes.ts"]`

`watch`

Array of strings

Defines a list of files or directories for Nodemon to **watch** for changes. Changes in these locations will cause Nodemon to restart the application.

`["../../../packages/*/dist/tsconfig.tsbuildinfo", "../../common/api/dist/tsconfig.tsbuildinfo", "src"]`

`ext`

String

File extensions that Nodemon should monitor. Only changes to files with these extensions will trigger restarts.

`"ts"` (TypeScript files)

`exec`

String

Command executed by Nodemon when restarting the application. It runs a build step first, then starts the Node.js server.

`"yarn build && node dist/bitcoin/api/src/app.js"`


Usage and Behavior

When Nodemon runs with this configuration:

  1. Watching Files:
    Nodemon watches the following:

    • TypeScript build info files located in relative paths:

      • ../../../packages/*/dist/tsconfig.tsbuildinfo

      • ../../common/api/dist/tsconfig.tsbuildinfo

    • The entire src directory.

  2. Ignoring Files:
    Changes to src/routes.ts are explicitly ignored and do not trigger a restart.

  3. File Extensions:
    Only files with the .ts extension are monitored.

  4. Execution on Restart:
    When a watched file changes, Nodemon runs the command:

    yarn build && node dist/bitcoin/api/src/app.js
    

    This means:

    • The project is rebuilt via yarn build (likely compiling TypeScript or bundling).

    • The Node.js application is launched from the compiled JavaScript entry point located at dist/bitcoin/api/src/app.js.


Important Implementation Details


Interaction with the System


Example Usage

To use this configuration, run Nodemon referencing this config file:

nodemon --config nodemon.json

Or if configured in `package.json` scripts:

"scripts": {
  "dev": "nodemon --config nodemon.json"
}

This will start Nodemon with the specified watch, ignore, extension, and execution rules.


Visual Diagram

Below is a flowchart demonstrating the workflow Nodemon follows based on this configuration:

flowchart TD
    A[Start Nodemon] --> B{File Change Detected?}
    B -- No --> B
    B -- Yes --> C{Is Changed File in "ignore"?}
    C -- Yes --> B
    C -- No --> D{Is Changed File Extension "ts"?}
    D -- No --> B
    D -- Yes --> E{Is Changed File in "watch"?}
    E -- No --> B
    E -- Yes --> F[Run "yarn build"]
    F --> G[Run "node dist/bitcoin/api/src/app.js"]
    G --> B

Summary

The `nodemon.json` file configures Nodemon to:

This setup facilitates efficient development by automating build and restart cycles, ensuring the app runs the latest code and coordinates builds across multiple related packages.