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.json
file.{ "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
nodemon
andts-node
:npm install nodemon ts-node --save-dev
-
Create a
nodemon.json
file: Create anodemon.json
configuration file in the root of your project to specify hownodemon
should handle TypeScript files.{ "watch": ["src"], "ext": "ts", "exec": "ts-node ./src/index.ts" }
-
Update
package.json
: Add a watch script to yourpackage.json
file.{ "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