difference between ts-node-dev and nodemon
To add a watch mode to TypeScript project using Node.js, you can use a tool like ts-node-dev or nodemon. These tools automatically restart your application whenever you make changes to your TypeScript files. Here's how to set it up:
Using ts-node-dev
-
Install
ts-node-dev:npm install ts-node-dev --save-dev -
Update
package.json: Add a watch script to yourpackage.jsonfile.{ "scripts": { "build": "tsc", "start": "node dist/index.js", "dev": "ts-node-dev --respawn --transpile-only src/index.ts" } } -
Run the watch script:
npm run dev
Using nodemon
-
Install
nodemonandts-node:npm install nodemon ts-node --save-dev -
Create a
nodemon.jsonfile: Create anodemon.jsonconfiguration file in the root of your project to specify hownodemonshould handle TypeScript files.{ "watch": ["src"], "ext": "ts", "exec": "ts-node ./src/index.ts" } -
Update
package.json: Add a watch script to yourpackage.jsonfile.{ "scripts": { "build": "tsc", "start": "node dist/index.js", "dev": "nodemon" } } -
Run the watch script:
npm run dev
Published on: Jun 26, 2024, 05:53 AM