How to Watch and Reload ts-node When TypeScript Files Change?

Restart ts-node automatically when your .ts files change using nodemon or ts-node-dev. Enhance your TypeScript workflow in real time.

Summarize with AI

Not enough time? get the key points instantly.

Use ts-node-dev or nodemon with ts-node to auto reload your app on TypeScript file changes. It’s faster and no more manual restarts.

Problem

When using ts-node in dev, any .ts file changes require manual restart of the process. That slows down NodeJS development and breaks the flow.

Solution

To auto reload your Node.js server when .ts files change, pair ts-node with a watcher like nodemon or ts-node-dev.

Option 1- ts-node-dev

bash

npm install -D ts-node-dev

Add script in package.json:

json

“scripts”: {“dev”: “ts-node-dev –respawn –transpile-only src/index.ts”

}

Run:

bash

npm run dev

Also Read: Node JS Best Practices to Adhere for Enhanced Performance & Security

Option 2- nodemon with ts-node

Install nodemon:

bash

npm install -D nodemon ts-node

Add script:

json

“scripts”: {“dev”: “nodemon –watch src -e ts –exec ts-node src/index.ts”

}

Conclusion

For fast dev, use ts-node-dev or nodemon with ts-node to auto-reload your app on file changes.


Resources

Insights from our engineering leaders.

Our team shares practical insights on the technologies and engineering decisions shaping enterprise software today, grounded in real client work.

NodeJS

Which Company Is Best for Hiring Node.js Developers in the UK?

Node.js helps businesses build backend systems, REST APIs, real-time applications, and SaaS platforms using JavaScript. Developing these solutions requires professionals who understand application architecture, technical…

NodeJS

How to tell if Node.js is installed or not?

To verify Node.js installation, run node -v or node --version. This checks if Node.js is installed and working correctly. Problem Before you run any Node.js…