How to Add Nodemon to your TS files

The dev package nodemon has been a great help providing server-side hot-reloading as we code in our JavaScript, json, and other files while developing the in the NodeJS environment. To include the benefits of nodemon in your TypeScript projects so that…


This content originally appeared on DEV Community and was authored by Meg Meyers

The dev package nodemon has been a great help providing server-side hot-reloading as we code in our JavaScript, json, and other files while developing the in the NodeJS environment. To include the benefits of nodemon in your TypeScript projects so that the unbuilt ts file hot-reloads as you go takes a bit more configuration, but isn't difficult.

Start by installing nodemon and ts-node as dev tools:

npm i -D nodemon ts-node

In the root of your project (on the same level as your package.json) made a config file called

nodemon.json

In this file, past the following code:

{
    "watch": ["src"],
    "ext":  "ts",
    "exec": "ts-node ./src/index.ts"
  }

The extensions I am watching with nodemon are simply the .ts files located in the src folder. The package ts-node will be used to execute the file called index.ts in my src folder. Update per your needs.

Put the following script in your package.json with your other scripts:

"nodemon": "nodemon --watch 'src/**/*.ts' --exec ts-node src/index.ts",

You will now be able to start your project using the following command:

nodemon

and as you code in the index.ts, the hot-reloading will update your server.

That's it for now!


This content originally appeared on DEV Community and was authored by Meg Meyers


Print Share Comment Cite Upload Translate Updates
APA

Meg Meyers | Sciencx (2024-06-21T23:13:03+00:00) How to Add Nodemon to your TS files. Retrieved from https://www.scien.cx/2024/06/21/how-to-add-nodemon-to-your-ts-files/

MLA
" » How to Add Nodemon to your TS files." Meg Meyers | Sciencx - Friday June 21, 2024, https://www.scien.cx/2024/06/21/how-to-add-nodemon-to-your-ts-files/
HARVARD
Meg Meyers | Sciencx Friday June 21, 2024 » How to Add Nodemon to your TS files., viewed ,<https://www.scien.cx/2024/06/21/how-to-add-nodemon-to-your-ts-files/>
VANCOUVER
Meg Meyers | Sciencx - » How to Add Nodemon to your TS files. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/21/how-to-add-nodemon-to-your-ts-files/
CHICAGO
" » How to Add Nodemon to your TS files." Meg Meyers | Sciencx - Accessed . https://www.scien.cx/2024/06/21/how-to-add-nodemon-to-your-ts-files/
IEEE
" » How to Add Nodemon to your TS files." Meg Meyers | Sciencx [Online]. Available: https://www.scien.cx/2024/06/21/how-to-add-nodemon-to-your-ts-files/. [Accessed: ]
rf:citation
» How to Add Nodemon to your TS files | Meg Meyers | Sciencx | https://www.scien.cx/2024/06/21/how-to-add-nodemon-to-your-ts-files/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.