nodemon.json
Overview
The `nodemon.json` file is a configuration file for **Nodemon**, a utility that monitors changes in source files and automatically restarts the Node.js application during development. This file specifies which files and directories Nodemon should watch or ignore, which file extensions trigger a restart, and the command to execute when changes are detected.
In this project, `nodemon.json` is used to streamline the development workflow by automatically rebuilding the TypeScript project and restarting the Node.js server whenever relevant source files or build artifacts change. This eliminates the need for manual restarts and helps maintain an efficient development cycle.
File Content and Explanation
{
"ignore": ["src/routes.ts"],
"watch": [
"../../../packages/*/dist/tsconfig.tsbuildinfo",
"../../common/api/dist/tsconfig.tsbuildinfo",
"src"
],
"ext": "ts",
"exec": "yarn build && node dist/gnosis/api/src/app.js"
}
Properties
Property | Type | Description |
|---|---|---|
`ignore` | array of strings | Specifies files or directories Nodemon should **ignore** and not watch for changes. Here, `src/routes.ts` is excluded from triggering a restart. |
`watch` | array of strings | Specifies files or directories Nodemon should **watch** for changes. Changes in these paths will trigger the `exec` command. Includes: |
`ext` | string | File extensions Nodemon should monitor. Here, set to `"ts"` to watch only TypeScript files. |
`exec` | string | The shell command Nodemon runs when a watched file changes. Here, it first runs `yarn build` to compile the project, then starts the Node.js server by running the compiled JavaScript file located at `dist/gnosis/api/src/app.js`. |
Usage Example
When a developer modifies any TypeScript files inside the `src` folder or when the build info files change (indicating a change in compiled output), Nodemon will:
Detect the change (except if it's
src/routes.ts, which is ignored).Run
yarn buildto recompile the TypeScript code.Execute the compiled server with
node dist/gnosis/api/src/app.js.Automatically restart the server if it was running.
This ensures that developers always run the latest build without manual intervention.
Implementation Details & Notes
Watching Build Info Files: The presence of
tsconfig.tsbuildinfofiles inwatchis a sophisticated approach to trigger rebuilds or restarts when incremental compilation occurs across multiple packages. This is useful in a monorepo or multi-package setup where changes in one package impact others.Ignoring
src/routes.ts: This file is explicitly excluded, possibly because changes here do not require a server restart or are handled differently, such as through hot module replacement or another mechanism.Command Execution: The command combines building and running in a single step (
yarn build && node ...). This ensures the server runs only if the build succeeds.
Interaction with the System
Build System Integration: This file is tightly coupled with the project's build system (
yarn build), which likely invokes the TypeScript compiler (tsc) or a bundler.Server Startup: The
execcommand runs the compiled output, which is the entry point of the Node.js server application.Development Workflow: Used during development to provide automatic rebuild and restart functionality, improving efficiency.
Monorepo Awareness: The paths in
watchsuggest this project is part of a larger monorepo structure.
Mermaid Diagram: Workflow of nodemon.json Configuration
The diagram below illustrates the workflow triggered by Nodemon based on the configuration in `nodemon.json`.
flowchart TD
A[File Change Detected] --> B{Is file ignored?}
B -- Yes --> C[No action]
B -- No --> D{Is file watched?}
D -- Yes --> E[Run "yarn build"]
E --> F{Build successful?}
F -- Yes --> G[Run "node dist/gnosis/api/src/app.js"]
F -- No --> H[Log build errors, do not restart]
D -- No --> C
Summary
The `nodemon.json` file is a concise but critical configuration that automates the development cycle by watching TypeScript source files and build metadata across a monorepo-style project. It ensures the application rebuilds and restarts seamlessly on relevant changes, thus supporting rapid development and testing of the Node.js backend service.
If you need further elaboration or integration details with other files, please provide additional context or related files.