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:
Specifies which files and directories Nodemon should watch for changes.
Defines file extensions that trigger Nodemon actions.
Sets the command to run when restarting the application.
Excludes specific files from triggering restarts.
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:
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
srcdirectory.
Ignoring Files:
Changes tosrc/routes.tsare explicitly ignored and do not trigger a restart.File Extensions:
Only files with the.tsextension are monitored.Execution on Restart:
When a watched file changes, Nodemon runs the command:yarn build && node dist/bitcoin/api/src/app.jsThis 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
Selective Watching with tsbuildinfo files:
The inclusion oftsconfig.tsbuildinfofiles from multiple packages indicates that the project uses TypeScript Project References or incremental builds. Watching these files allows Nodemon to detect when builds of dependent packages complete, ensuring the main app restarts only after dependencies are rebuilt.Ignoring Specific Files:
The explicit ignore forsrc/routes.tssuggests that changes in this file might be handled differently (e.g., hot-reloaded via a different mechanism) or that it causes noisy restarts unnecessary for development.Build-Then-Run Strategy:
Theexeccommand encapsulates a two-step process—build then run—to ensure the running application is always up to date with the latest code changes.
Interaction with the System
Integration in the Development Workflow:
This file is part of the development environment setup. Developers run Nodemon with this configuration to get automatic rebuilds and restarts on source changes, enhancing productivity and reducing manual steps.Relationship to Build System:
Theyarn buildcommand depends on the project's build scripts and tooling (likely TypeScript compiler and bundlers). Thenodemon.jsonensures this build is triggered on every restart.Relation to Application Entry Point:
Theexeccommand starts the Node.js server from the compiled output located underdist/bitcoin/api/src/app.js. This means the source files insrcare compiled intodistbefore running.Cross-Package Coordination:
Watchingtsbuildinfofiles in other packages implies that this project is part of a monorepo or multi-package repository, coordinating builds across packages.
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:
Watch specific TypeScript source directories and build info files.
Ignore specific files that should not trigger restarts.
Restrict monitoring to
.tsfiles.Run a build command followed by starting the compiled Node.js application on each restart.
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.