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
Add script in package.json:
json
“scripts”: {“dev”: “ts-node-dev –respawn –transpile-only src/index.ts”
}
Run:
bash
Also Read: Node JS Best Practices to Adhere for Enhanced Performance & Security
Option 2- nodemon with ts-node
Install nodemon:
bash
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.