nodemon --exec ts-node versus precompiled JavaScript: a restart decision guide
Decide whether to run TypeScript directly with nodemon --exec ts-node or compile to JavaScript first, including config examples and restart trade-offs.
29 Jul 2025, 18:10 UTC

The problem: restart TypeScript without a manual build step
You are editing src/index.ts and want the running Node process to restart on save. nodemon can watch files and restart the process, but TypeScript cannot be executed by Node directly. You must either run the TypeScript through an interpreter such as ts-node, or compile it to JavaScript first and point nodemon at the emitted output. Each path changes restart speed, type safety, and the risk of restart loops.
Useful takeaway: choose nodemon --exec ts-node for local development when immediate feedback matters. Choose precompiled JavaScript when you want full tsc type-checking before execution or need the running code to match the production build exactly.
Constraints to decide against
- Team members should not have to remember different CLI flags.
- Bulk file saves should not trigger a restart storm.
- Generated output directories must not be watched, or nodemon can restart repeatedly.
- Local tooling should not replace a full type-check in CI.
Supported options compared
| Option | Typical command | Type checking | Build step | Best suited for |
|---|---|---|---|---|
| nodemon --exec ts-node | nodemon --exec ts-node src/index.ts | Limited, performed by ts-node | None | Fast local development feedback |
| tsc then nodemon on .js | tsc, then nodemon dist/index.js | Full, performed by tsc before emit | Required | Production-like execution path |
| Plain nodemon on .js | nodemon dist/index.js | None | Required, handled externally | JavaScript-only projects |
Trade-offs
nodemon --exec ts-node
The --exec flag tells nodemon to launch the target script through an interpreter instead of Node directly. With ts-node, TypeScript is transpiled and executed in one step. Edits to .ts files trigger a restart without a separate tsc run. The downside is that ts-node performs limited type checking; some type errors reach runtime instead of failing at compile time.
Precompiled JavaScript
Running tsc first catches type errors before nodemon ever starts the process. The emitted JavaScript runs under plain Node, which matches production more closely. The cost is an extra build step and slower feedback after every edit unless you also run tsc --watch in parallel.
Restart delay
If you save many files at once, nodemon may restart repeatedly. The --delay option adds a quiet period before restarting. A value of 500 to 1000 milliseconds is a practical starting point.
Implementation: shared nodemon.json
Create nodemon.json in the project root so every team member gets the same watch and restart behavior without repeating flags.
{
"exec": "ts-node",
"script": "src/index.ts",
"watch": ["src"],
"ignore": ["dist", "node_modules", "*.test.ts"],
"ext": "ts,json",
"delay": 500
}
Where to run: terminal at the project root.
Permissions: no elevated permissions required; the user must be able to read the project files and execute nodemon.
Expected checks:
nodemon --versionprints a version number, confirming the CLI is installed.- Running
nodemonstarts ts-node and loadssrc/index.ts. - Saving a change to
src/index.tsproduces a restart message without a manualtsccommand.
Risk: ts-node does not replace tsc --noEmit. Type errors may appear at runtime. Watching the dist directory can create a restart loop because compiled output changes trigger nodemon, which triggers more compilation. The ignore array above prevents that.
Validation
- Run
nodemon --versionto confirm the CLI responds. - Start
nodemon --exec ts-node src/index.ts, or simplynodemonifnodemon.jsonis present. - Modify a source file in
srcand save. - Confirm nodemon logs a restart and the process continues without manual rebuild.
- Run
npx tsc --noEmitseparately to verify type errors are caught outside the nodemon loop.
Limitations
This guide covers local development restarts. It does not cover production process management, cluster mode, or debugging configuration. ts-node behavior may vary by version; pin the dependency in package.json for consistent results across a team.
Practical way to check the result: after editing a TypeScript file, confirm the terminal shows a nodemon restart line and the application behaves as expected. If no restart occurs, check that the edited file extension matches ext in nodemon.json and that the file is not listed in ignore.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.