Configuring Nodemon with TypeScript

Master automatic TypeScript reloading with nodemon. From zero-config setups to advanced customization for production-grade development workflows.

Why Configure Nodemon for TypeScript?

TypeScript has become the standard for modern Node.js development, offering type safety and improved developer experience. However, TypeScript requires compilation before execution, which complicates the typical development workflow.

Nodemon is a powerful tool that automatically restarts your Node.js application when file changes are detected. When properly configured for TypeScript, it eliminates the need for manual compilation and server restarts--transforming your development experience with instant feedback on every change.

What you'll learn:

  • Three methods to configure nodemon with TypeScript
  • Performance optimization strategies
  • Common troubleshooting solutions
  • When to consider alternative tools like ts-node-dev or tsx

For teams building complex applications, proper development tooling configuration is essential for maintaining velocity. Learn more about our approach to web development best practices that prioritize developer productivity.

Nodemon Configuration Options

3

Configuration Methods

v1.19.0+

Built-in TS Support

10+

Configurable Options

4

Restart Behaviors

Method 1: No-Config Workflow (Since nodemon v1.19.0)

Modern versions of nodemon include built-in TypeScript support, eliminating the need for complex configuration in most scenarios.

Prerequisites

# Install nodemon and ts-node as development dependencies
npm install --save-dev nodemon ts-node
# or
yarn add --dev nodemon ts-node

Running TypeScript Files

# Simply pass your TypeScript entry file to nodemon
npx nodemon index.ts

Nodemon automatically detects TypeScript files and uses ts-node to compile and execute them. The tool watches for changes and restarts your application instantly.

When This Approach Works Best

The no-config workflow excels in several scenarios. Small to medium projects with straightforward TypeScript setups benefit immediately without spending time on configuration. If your project uses default TypeScript compiler options without custom paths, transformers, or plugins, the built-in support handles everything seamlessly.

Prototyping and learning environments prove ideal for this approach since you can focus on code rather than tooling. Single entry point applications with a simple structure--where changes typically affect a predictable set of files--work well with zero configuration.

Limitations

Despite its simplicity, the no-config approach has boundaries. Custom ts-node flags cannot be easily passed when relying solely on automatic detection. Projects with multiple tsconfig.json files, such as monorepos or applications using different configurations for different entry points, may encounter challenges with the automatic setup.

Teams requiring specific compilation behavior--like enforcing strict type checking during development, using custom module resolvers, or applying specific compiler transforms--will need manual configuration. Additionally, if you need to integrate with external tools or execute pre-start scripts, the no-config workflow provides insufficient flexibility.

Real-world scenario: A REST API project with 15 endpoints and database integration using Prisma works fine with no-config, but that same API with custom webpack builds, environment-specific configurations, and pre-compilation asset processing requires manual setup.

Method 2: Manual Configuration with nodemon.json

For projects requiring fine-grained control, manual configuration through nodemon.json provides maximum flexibility while keeping all settings in one discoverable location.

Creating Your Configuration File

Create a nodemon.json file in your project root with the following structure:

{
 "execMap": {
 "ts": "ts-node"
 },
 "watch": ["src"],
 "ignore": ["src/**/*.spec.ts", "src/**/*.test.ts"],
 "delay": "2500",
 "ext": "ts,json"
}

Key Configuration Options Explained

execMap tells nodemon which executable to use for specific file extensions. The "ts" key maps TypeScript files (.ts and .tsx) to ts-node. You can extend this for other file types or replace ts-node with faster alternatives like tsx:

{
 "execMap": {
 "ts": "tsx",
 "mts": "tsx"
 }
}

watch defines directories to monitor for changes. For most projects, watching the src directory suffices. Larger projects might watch specific subdirectories to reduce unnecessary restarts:

{
 "watch": ["src/api", "src/services", "src/utils"]
}

ignore prevents nodemon from watching files that shouldn't trigger restarts. Essential patterns include test files, build outputs, and configuration files that change frequently but don't affect runtime behavior:

{
 "ignore": [
 "node_modules",
 "dist",
 "build",
 ".next",
 "**/*.spec.ts",
 "**/*.test.ts",
 "*.config.js",
 "coverage"
 ]
}

delay specifies milliseconds to wait before restarting after file changes. This prevents rapid successive restarts during bulk saves or build processes. A 2500ms delay typically balances responsiveness with stability.

ext tells nodemon which file extensions to monitor. The default includes JavaScript files, but for TypeScript projects, explicitly include ts and related extensions:

{
 "ext": "ts,tsx,json,mjs,cjs"
}

Alternative: Configuration in package.json

For simpler projects, embedding nodemon configuration in package.json eliminates an additional file:

{
 "name": "my-typescript-app",
 "version": "1.0.0",
 "nodemonConfig": {
 "execMap": {
 "ts": "ts-node --project tsconfig.app.json"
 },
 "watch": ["src"],
 "ignore": ["src/**/*.spec.ts", "src/**/*.test.ts"],
 "delay": "1000",
 "ext": "ts,json"
 }
}

This approach works well for smaller projects where configuration complexity doesn't warrant a dedicated file. However, nodemon.json scales better for projects with extensive monitoring requirements.

For enterprise applications with complex TypeScript configurations, consider partnering with a web development agency that can optimize your entire development workflow.

Method 3: Custom Execution Command

For maximum flexibility, use the --exec flag to run custom commands with nodemon. This approach provides the highest degree of control over how TypeScript files are processed.

Basic Usage

# Run with ts-node and custom flags
nodemon --exec "ts-node --project tsconfig.app.json" src/index.ts

# Use tsx for faster execution
nodemon --exec "tsx" src/index.ts

# Run build script then execute
nodemon --exec "npm run build && node dist/index.js"

Environment-Specific Configurations

Different environments often require different TypeScript configurations. The --exec approach handles this elegantly:

# Development with full type checking
nodemon --exec "ts-node --project tsconfig.dev.json" src/index.ts

# Staging with relaxed type checking for faster iteration
nodemon --exec "ts-node --transpileOnly --project tsconfig.json" src/index.ts

# Production-like build verification
nodemon --exec "npm run build && NODE_ENV=production node dist/index.js" src/index.ts

Integrating with Different TypeScript Configs

Monorepos and complex projects frequently use multiple tsconfig files. Reference the appropriate configuration based on the context:

# API server with database types
nodemon --exec "ts-node --project tsconfig.api.json" src/api/index.ts

# Background worker with job queue types
nodemon --exec "ts-node --project tsconfig.worker.json" src/worker/index.ts

# Using swc for faster compilation in node_modules
nodemon --exec "ts-node --transpileOnly --compilerOptions '{\"module\":\"commonjs\"}'" src/index.ts

Creating npm Script Aliases

Add convenient scripts to your package.json for consistent team workflows:

{
 "scripts": {
 "dev": "nodemon --exec ts-node src/index.ts",
 "dev:fast": "nodemon --exec tsx src/index.ts",
 "dev:watch": "nodemon --watch src --ext ts --exec 'npm run build && node dist/index.js'",
 "dev:api": "nodemon --exec 'ts-node --project tsconfig.api.json' src/api/server.ts",
 "dev:debug": "nodemon --exec 'ts-node --inspect=9229' src/index.ts"
 }
}

Advanced Patterns

# With environment variables for database connections
nodemon --exec "DATABASE_URL=postgres://localhost:5432/myapp ts-node" src/index.ts

# Using ts-node-esm for ES modules
nodemon --exec "ts-node-esm --project tsconfig.esm.json" src/index.ts

# Custom compiler with transpile-only mode for speed
nodemon --exec "ts-node --transpileOnly --skipProject" src/index.ts

# Debugging with Chrome DevTools
nodemon --exec "ts-node --inspect-brk=9229 --project tsconfig.json" src/index.ts

# Combining with webpack or other bundlers
nodemon --exec "webpack serve --mode development" --watch webpack.config.js

These patterns integrate seamlessly with modern development tools including VS Code debugging and Docker container workflows.

Performance Optimization Best Practices

Optimizing nodemon configuration is crucial for maintaining fast development cycles, especially as projects grow in size and complexity. The difference between a well-configured and poorly-configured setup can mean seconds or minutes of lost productivity per day.

Optimize Watch Patterns

{
 "watch": ["src"],
 "ignore": [
 "node_modules",
 "dist",
 "build",
 "**/*.spec.ts",
 "**/*.test.ts",
 "*.config.js",
 "coverage",
 ".git"
 ]
}

Key optimizations for watch patterns:

Only watch source directories, never node_modules or build outputs. Exclude test files to prevent restarts during test runs. Use specific watch paths rather than watching the entire project root--targeting "src" instead of "." can significantly reduce file system events on larger projects.

Consider using glob patterns for more granular control:

{
 "watch": ["src/**/*.{ts,tsx}"],
 "ignore": ["src/**/*.d.ts", "src/**/*.spec.ts"]
}

Faster TypeScript Compilation

Consider using faster alternatives to ts-node for improved performance:

# Install tsx (Rust-based, significantly faster)
npm install --save-dev tsx

# Run with tsx instead of ts-node
nodemon --exec "tsx" src/index.ts

tsx, written in Rust, typically provides 10-20x faster startup time compared to ts-node while maintaining compatibility with most TypeScript projects. For projects using ESM modules, tsx handles native ESM without additional configuration.

Memory and Resource Management

Nodemon runs as a separate process, and on larger projects, memory usage can become noticeable. Monitor your development environment's resource consumption--projects with hundreds of TypeScript files may benefit from restarting nodemon periodically during extended development sessions.

The --max-old-space-size flag helps Node.js manage memory more effectively:

nodemon --exec "node --max-old-space-size=4096 ts-node" src/index.ts

For TypeScript-specific optimization, ts-node-dev provides smart restarts that only recompile changed files and their dependencies, reducing both memory usage and restart times.

Comparison: TypeScript Runners

RunnerStartup TimeExecution SpeedType SafetyBest For
ts-nodeSlowMediumFullComplex type checking
ts-node --transpileOnlyMediumMediumNoneFast iteration
tsxFastFastFullGeneral use
ts-node-devFastFastFullActive development

For most projects, tsx provides the best balance of speed and compatibility. Reserve ts-node with full type checking for situations where you need strict type validation during development.

Developer productivity tip: The right tooling can significantly impact your team's velocity. Our web development services include workflow optimization to help teams ship faster.

ts-node-dev: TypeScript-Specific Development Server

ts-node-dev combines ts-node with nodemon's file-watching capabilities, specifically designed for TypeScript development with smart restart behavior.

# Installation
npm install --save-dev ts-node-dev

# Basic usage with automatic respawn
ts-node-dev --respawn src/index.ts

# With custom TypeScript config
ts-node-dev --project tsconfig.json src/index.ts

# Suppress compilation warnings
ts-node-dev --quiet src/index.ts

When ts-node-dev excels:

The tool's smart restart mechanism only recompiles changed files and their dependencies, making it significantly faster than nodemon plus ts-node for larger projects. If you're working on a complex application with deep import chains, this optimization can reduce restart times from seconds to milliseconds.

Express.js APIs with frequent file changes benefit greatly from ts-node-dev's incremental compilation. The --debounce flag further controls restart behavior, preventing rapid restarts during continuous file saves.

# With debounce to prevent rapid restarts
ts-node-dev --debounce 1000 --respawn src/index.ts

ts-node-dev works particularly well with projects using Prisma or ORMs where database schema changes require application restarts.

Choosing the Right Configuration Method

Selecting the appropriate nodemon configuration depends on your project's complexity and requirements:

MethodBest ForComplexityFlexibility
No-Config (v1.19.0+)Simple projects, prototypesLowLow
nodemon.jsonProduction projectsMediumHigh
Custom --execComplex workflowsMediumVery High
ts-node-devTypeScript-focused developmentLowMedium
pm2Production environmentsHighVery High

Quick Start Recommendations

New project starting out? Start with the no-config workflow. Run npx nodemon index.ts and upgrade to nodemon.json as your needs grow.

Existing project with custom tsconfig? Create a nodemon.json with execMap configuration matching your TypeScript setup. This provides discoverable configuration for your team.

Complex build process? Use custom --exec commands to integrate build steps. Create npm scripts in package.json for consistent team workflows.

Maximum TypeScript performance? Consider ts-node-dev or tsx for faster development cycles. These tools specifically optimize the TypeScript development experience.

Migration Path Between Methods

Migrating from no-config to nodemon.json requires three steps:

  1. Create nodemon.json with execMap: {"execMap": {"ts": "ts-node"}}
  2. Add any custom watch and ignore patterns
  3. Test that npx nodemon respects the new configuration

Team best practices:

  • Document your chosen configuration in CONTRIBUTING.md
  • Use npm scripts rather than command-line flags for consistency
  • Version control your nodemon.json file
  • Standardize configuration across team members' environments
  • Consider creating a .nodemonignore file for project-specific exclusions

Next Steps

  1. Assess your current setup - Check nodemon version and current configuration
  2. Identify pain points - Slow restarts? Missing features? Configuration issues?
  3. Choose appropriate method - Match configuration to your project size and complexity
  4. Optimize performance - Refine watch patterns and consider faster runners like tsx
  5. Document your configuration - Ensure team consistency across development environments

For larger applications requiring enterprise-grade tooling, consider integrating your nodemon setup with our custom web development services to build a complete development infrastructure tailored to your project's specific needs.

Need Help Optimizing Your TypeScript Development Workflow?

Our team of experienced developers can help you set up efficient development tooling tailored to your project's specific requirements.

Frequently Asked Questions

What version of nodemon supports TypeScript without configuration?

Nodemon version 1.19.0 and above include built-in TypeScript support through ts-node. Simply install both packages as devDependencies and run nodemon with TypeScript files directly.

How do I configure nodemon to watch specific directories only?

Use the 'watch' option in nodemon.json: `{"watch": ["src"]}`. This tells nodemon to only monitor the 'src' directory for changes, ignoring other project files and folders.

What's faster: ts-node or tsx?

tsx is significantly faster than ts-node because it's written in Rust. tsx can be 10-20x faster for startup time and generally provides better performance for TypeScript execution.

How do I prevent infinite restart loops?

Add a delay in your configuration: `{"delay": "2500"}` for 2.5 seconds. Also ensure build output directories are in the ignore list: `{"ignore": ["dist/**", "build/**"]}`.

Can I use nodemon with Docker?

Yes, but you'll need to use polling mode for file watching: `nodemon --legacy-watch`. Volume mount your source code and ensure the container has sufficient resources for file system monitoring.

How do I debug TypeScript with nodemon?

Use the --inspect flag with ts-node: `nodemon --exec "ts-node --inspect" src/index.ts`. Then attach your debugger (VS Code, Chrome DevTools) to the Node.js debugging port.

Sources

  1. nodemon npm package - Official documentation for nodemon, the tool that monitors for any changes in your Node.js application and automatically restarts the server.

  2. ts-node-dev GitHub - TypeScript execution engine that combines ts-node with nodemon-like file watching for faster restarts.

  3. DigitalOcean Nodemon Tutorial - Community tutorial on setting up, configuring, and troubleshooting nodemon workflows.

  4. LogRocket: Configuring nodemon with TypeScript - Comprehensive guide covering three methods of nodemon TypeScript configuration.

  5. DEV Community: Configuring nodemon with TypeScript - Tutorial on no-config workflow and custom execution commands.