My approach in October of 2018 utilizing the latest versions of nodemon.
Step one:
Firstly, you need to install nodemon
(npm install nodemon --save-dev
) and ts-node
(npm install ts-node --save-dev
).
Step two:
Next, create a nodemon.json
. I prefer keeping my nodemon configuration separate in a nodemon.json file to make npm scripts easier to understand. Create the nodemon.json
in the project root with the following contents:
{
"ignore": ["**/*.test.ts", "**/*.spec.ts", ".git", "node_modules"],
"watch": ["src"], // your .ts source folder
"exec": "npm start", // your npm script defined in package.json
"ext": "ts"
}
After that, set up your npm start
script like this:
"scripts": {
...
"start": "ts-node src/server.ts",
"dev:ts": "nodemon",
...
}
Now, running npm run dev:ts
or yarn dev:ts
will execute and monitor your TypeScript server code.
To explore additional configurations like setting up Jest
unit tests, refer to this article.