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