nodemon.json
Overview
`nodemon.json` is a configuration file used to customize the behavior of [Nodemon](https://nodemon.io/), a utility that monitors changes in source files and automatically restarts the node application. This file defines specific settings such as which files to watch or ignore, file extensions to monitor, and the command to execute when a change is detected.
In this project, `nodemon.json` configures Nodemon to:
Ignore changes in certain files (e.g.,
src/routes.ts).Watch specific files and directories, including build info files and source code.
Monitor files with a
.tsextension (TypeScript files).Execute a build command followed by launching the compiled Node.js application.
This setup streamlines the development workflow by automating build and restart processes whenever relevant source files are updated.
Configuration Properties
The file is a JSON object with the following key properties:
Property | Type | Description |
|---|---|---|
`string[]` | List of file paths or patterns to be ignored by Nodemon. Changes to these files will not trigger a restart. | |
`watch` | `string[]` | List of file paths or patterns that Nodemon should monitor for changes. When any of these files change, Nodemon restarts the app. |
`ext` | `string` | File extensions that Nodemon should watch for changes. In this case, `.ts` (TypeScript files). |
`exec` | `string` | Command to execute when a watched file changes. Here, it runs a TypeScript build followed by starting the Node.js app. |
Detailed Explanation of Each Property
1. ignore
Purpose: Prevent Nodemon from restarting the app on changes in certain files.
Configured Value:
["src/routes.ts"]Reasoning: The file
src/routes.tsis excluded from triggering restarts, possibly because changes in this file either do not require a full restart or it is managed differently (e.g., hot-reloaded separately or stable during development).
2. watch
Purpose: Specify which files/directories Nodemon should monitor for changes.
Configured Value:
[ "../../../packages/*/dist/tsconfig.tsbuildinfo", "../../common/api/dist/tsconfig.tsbuildinfo", "src" ]Explanation:
It watches TypeScript build info files (
tsconfig.tsbuildinfo) from packages and common API directories — these files indicate incremental TypeScript compilation status.It watches the
srcdirectory, which likely contains source TypeScript code.
Effect: When any of these watched files change, Nodemon triggers the restart sequence.
3. ext
Purpose: Limits Nodemon’s file monitoring to specific file extensions.
Configured Value:
"ts"Explanation: Nodemon only listens for changes in
.tsfiles, ignoring other file types to reduce unnecessary restarts.
4. exec
Purpose: Defines the shell command to run when a watched file changes.
Configured Value:
"yarn build && node dist/polygon/api/src/app.js"Explanation:
First,
yarn buildcompiles the TypeScript source code into JavaScript.Then,
node dist/polygon/api/src/app.jsruns the compiled server application.
Effect: Ensures that the latest build is executed after every code change, maintaining synchronization between source and running app.
Usage Example
Assuming Nodemon is installed and configured to use this `nodemon.json` file, running:
nodemon
will:
Start watching files as configured.
On detecting a
.tsfile change in thesrcdirectory or the specifiedtsconfig.tsbuildinfofiles, it will run the build command and restart the Node.js app.Ignore changes to
src/routes.ts.
This is ideal for development cycles involving TypeScript code where automatic rebuild and restart improve productivity.
Implementation Details
Incremental TypeScript Build Awareness:
Watchingtsconfig.tsbuildinfofiles helps Nodemon detect when TypeScript incremental builds complete. This is a subtle optimization ensuring Nodemon only restarts after successful builds rather than on every file write.Modular Project Structure:
The paths indicate a monorepo or multi-package repository layout with shared code (common/api) and packages under../../../packages. Thenodemon.jsonconfig is tailored to coordinate across this structure.Build-Then-Run Workflow:
Theexeccommand enforces a sequential build-then-run step, ensuring the running app always reflects the latest compiled sources.
Interaction with Other System Parts
TypeScript Compiler (
tsc):
The file indirectly interacts with the TypeScript compiler via theyarn buildscript, which presumably runstscor an equivalent build tool.Application Entry Point:
The pathdist/polygon/api/src/app.jspoints to the compiled JavaScript entry point for the API server part of the system.Project Build System:
Theyarn buildcommand suggests integration with the project's package manager and build scripts, which handle compilation and possibly bundling.Development Workflow:
This file is part of the developer tooling ecosystem, enabling hot reload-like functionality without implementing explicit hot module replacement.
Visual Diagram
flowchart TD
A[Nodemon] -->|Watches| B[tsconfig.tsbuildinfo files]
A -->|Watches| C[src/*.ts files]
A -->|Ignores| D[src/routes.ts]
B --> E{File Change Detected?}
C --> E
E -->|Yes| F[yarn build]
F --> G[node dist/polygon/api/src/app.js]
E -->|No| A
**Diagram Explanation:**
Nodemon monitors specific build info files and source
.tsfiles exceptsrc/routes.ts.When a file changes, Nodemon runs the build command (
yarn build).After the build finishes, Nodemon starts the compiled Node.js application.
If no relevant files change, Nodemon continues monitoring.
Summary
The `nodemon.json` file is a minimal yet critical configuration that orchestrates automatic rebuilds and restarts of the Node.js application during development. It tailors Nodemon's file watching capabilities to the project's TypeScript environment and multi-package structure, enhancing developer efficiency by automating repetitive build and restart steps.
If you require further customization or integration, consider extending this file with additional options such as environment variables, delay times, or custom restart logic as supported by Nodemon.