nodemon.json
Overview
The [nodemon.json](/projects/291/68849) file is a configuration file used by **Nodemon**, a utility that monitors for any changes in your source code and automatically restarts your Node.js application. This particular configuration governs how Nodemon watches files, which files to ignore, which file extensions to monitor, and what command to execute upon changes.
In this project, the [nodemon.json](/projects/291/68849) file is tailored for a TypeScript-based Node.js application. It ensures that the application rebuilds using `yarn build` before restarting the server whenever relevant files change. This automation streamlines the development workflow by reducing manual steps and helping maintain up-to-date builds during development.
Detailed Explanation of Configuration Properties
This JSON file does not contain classes or functions but consists of key-value pairs defining Nodemon behavior.
Property | Type | Description | Example / Notes |
|---|---|---|---|
`ignore` | Array of strings | Specifies files or directories that Nodemon should **not** watch for changes. Useful for ignoring files that do not affect the running app or would trigger unnecessary restarts. | [["src/routes.ts"]](/projects/291/69202) - Changes to this file will be ignored by Nodemon. |
Array of strings | Defines files or directories that Nodemon **should** watch for changes. When these files change, Nodemon triggers the specified command. This is useful to explicitly monitor build artifacts or source code. | [["../../../packages/*/dist/tsconfig.tsbuildinfo", "../../common/api/dist/tsconfig.tsbuildinfo", "src"]](/projects/291/68809) watches specific build info files and the `src` directory. | |
String | Specifies the file extensions Nodemon should monitor. This restricts watching to files with these extensions. | `"ts"` means only TypeScript files trigger restarts. | |
String | The command Nodemon executes when a watched file changes. This typically rebuilds the project and runs the application. | ["yarn build && node dist/bnbsmartchain/api/src/app.js"](/projects/291/68852) runs the build script and then starts the Node.js app at the compiled location. |
Usage Example
When running Nodemon with this configuration (either by placing this [nodemon.json](/projects/291/68849) in the root directory or specifying it with the [-c](/projects/291/68956) option), the development workflow is as follows:
Nodemon watches for changes in:
All TypeScript files under
srcSpecific build info files generated by TypeScript incremental compilation in relative package directories
Changes to src/routes.ts are ignored to prevent unnecessary restarts.
When a relevant file changes:
Nodemon runs
yarn buildto compile TypeScript to JavaScript.After a successful build, Nodemon runs the Node.js application located at
dist/bnbsmartchain/api/src/app.js.
The application restarts automatically with the latest code.
This setup is especially helpful in monorepo or multi-package projects where incremental builds are monitored via [tsconfig.tsbuildinfo](/projects/291/68809) files.
Important Implementation Details
Watching
.tsfiles only: Restricts Nodemon to monitor only TypeScript files. This reduces noise from unrelated files.Watching tsconfig.tsbuildinfo files: These files are generated by TypeScript's incremental build feature and their changes indicate a change in the build output state. Watching them helps trigger restarts when dependent compiled code changes.
Ignoring src/routes.ts: This might be a deliberate choice because this file is either stable or changes to it do not require a full rebuild and restart (e.g., it might be handled by another hot-reload mechanism).
Sequential execution in exec: The command runs
yarn buildfirst, and only if successful, runs the Node.js app. This prevents starting the app with stale or broken builds.
Interaction with Other System Components
Build System: The exec command runs
yarn build, which likely triggers the TypeScript compiler and/or other build tools configured in the project. This file indirectly depends on the build scripts defined elsewhere (e.g., inpackage.json).Compiled Output: The Node.js executable path
dist/bnbsmartchain/api/src/app.jsindicates that the source TypeScript code is compiled into adist/directory structure. This configuration assumes the build outputs are placed correctly.Source Code: Watches the
srcdirectory where active development occurs.Monorepo Structure: Watching relative paths like ../../../packages/*/dist/tsconfig.tsbuildinfo implies this project is part of a larger monorepo with multiple packages.
Mermaid Diagram: Workflow of nodemon.json Configuration
This flowchart illustrates the event-driven workflow Nodemon follows based on this configuration:
flowchart TD
A[Start Nodemon] --> B[Watch .ts files in src + tsbuildinfo files]
B --> C{File Changed?}
C -- No --> B
C -- Yes --> D{Is Changed File in ignore list?}
D -- Yes --> B
D -- No --> E[Run "yarn build"]
E --> F{Build Successful?}
F -- No --> B
F -- Yes --> G[Run "node dist/bnbsmartchain/api/src/app.js"]
G --> B
Summary
[nodemon.json](/projects/291/68849) configures Nodemon to enhance the development experience by:
Watching relevant TypeScript source files and build info artifacts to detect meaningful code changes.
Ignoring specific files to prevent redundant restarts.
Automatically rebuilding the project before restarting the Node.js server.
Supporting a multi-package project structure through relative watch paths.
This file is a critical piece in the automated development loop, ensuring that changes are swiftly compiled and reflected in the running application without manual intervention.