nodemon.json
Overview
The [nodemon.json](/projects/291/68849) file is a configuration file used by **nodemon**, a utility that monitors changes in source code files and automatically restarts the Node.js application when changes are detected. This configuration customizes the behavior of nodemon specifically for a TypeScript-based Node.js project, streamlining the development workflow by automating rebuild and restart processes.
In this particular setup, [nodemon.json](/projects/291/68849) specifies which files and directories to watch or ignore, the file extensions to monitor, and the exact command to execute when a restart is triggered. This ensures efficient development iterations by rebuilding the project and launching the application automatically upon relevant source changes.
Configuration Properties
The JSON object in the file contains four key properties:
{
"ignore": [...],
"watch": [...],
"ext": "...",
"exec": "..."
}
1. ignore
Type: Array of strings
Purpose: Specifies files or directories that nodemon should ignore and not watch for changes.
Value in this file:
["src/routes.ts"]Usage: This setting prevents nodemon from restarting the app when
src/routes.tschanges. This might be done to avoid unnecessary rebuilds during changes that do not affect the runtime or that are handled differently.
2. watch
Type: Array of strings
Purpose: Specifies which files or directories nodemon should watch for changes.
Value in this file:
[ "../../../packages/*/dist/tsconfig.tsbuildinfo", "../../common/api/dist/tsconfig.tsbuildinfo", "src" ]Usage: Nodemon monitors the specified TypeScript build info files and the
srcdirectory. When any changes occur in these paths/files, nodemon triggers the restart process.Notes: The
tsconfig.tsbuildinfofiles store incremental build information used by TypeScript for faster builds. Watching these files ensures that changes in package builds trigger nodemon restarts.
3. ext
Type: String
Purpose: Defines file extensions to watch for changes.
Value:
"ts"Usage: Restricts nodemon to watch only files with a
.tsextension (TypeScript files), ignoring all others like.js,.json,.md, etc.
4. exec
Type: String
Purpose: Defines the command nodemon should execute when a watched file changes.
Value:
"yarn build && node dist/dogecoin/api/src/app.js"Usage: On detecting changes, nodemon first runs
yarn build(likely to compile TypeScript sources into JavaScript), and upon successful build, it runs the Node.js application entry point located atdist/dogecoin/api/src/app.js.Notes: This ensures the app always runs the latest compiled code.
Implementation Details
Build Automation: By combining the build command and the node execution in a single
execstring with&&, nodemon ensures the app restarts only after a successful build.Selective Watching: The use of
ignoreandwatcharrays allows fine-grained control over what triggers restarts, optimizing performance and avoiding unnecessary rebuilds.Incremental Build Awareness: Watching
tsconfig.tsbuildinfofiles suggests the project uses incremental builds (tsc --incremental), so the build info files are critical for detecting changes in compiled packages.Relative Paths: The paths in
watchuse relative paths with../../and../../../, indicating this configuration is part of a multi-package or monorepo structure where several packages are built and watched collectively.
Interaction with Other Parts of the System
Build System: The
yarn buildcommand is expected to be defined in the project'spackage.jsonscripts. It likely triggers the TypeScript compiler or a build tool to transpile.tsfiles into.js.Application Entry Point: The
node dist/dogecoin/api/src/app.jscommand runs the compiled JavaScript app. This file is the main server or API entry point.Source Code (
src): Nodemon watches thesrcdirectory, which contains the raw TypeScript source files for this application.Monorepo Packages: The watch paths referencing
../../../packages/*/dist/tsconfig.tsbuildinfoand../../common/api/dist/tsconfig.tsbuildinfoimply dependencies on other internal packages. Changes in these packages' build info files trigger a rebuild and restart of this app.Development Workflow: This setup automates continuous rebuild and restart during development, enabling rapid feedback and testing.
Usage Example
When a developer modifies a `.ts` file in `src` or updates a package's build info file:
Nodemon detects the change.
Runs
yarn buildto compile the TypeScript project.If the build succeeds, nodemon runs
node dist/dogecoin/api/src/app.jsto start the latest app version.If the build fails, nodemon does not restart, allowing the developer to fix errors.
Mermaid Flowchart Diagram
This flowchart illustrates the workflow triggered by nodemon configuration in this file:
flowchart TD
A[File Change Detected]
B{Is changed file in "ignore"?}
C{Is changed file in "watch" with extension .ts?}
D[Run "yarn build"]
E{Build successful?}
F[Run "node dist/dogecoin/api/src/app.js"]
G[No action]
A --> B
B -- Yes --> G
B -- No --> C
C -- No --> G
C -- Yes --> D
D --> E
E -- Yes --> F
E -- No --> G
Summary
The nodemon.json file configures nodemon for a TypeScript Node.js project.
It ignores specific files, watches source and build info files, and triggers a build-and-run command on changes.
This setup optimizes development by automating rebuilds and restarts.
It integrates with a monorepo-style project structure and supports incremental builds.
The configuration ensures that the application always runs the latest compiled code after relevant source changes.