If you want to effortlessly set up your development environment, just use
npm install --save-dev ts-node nodemon
and then execute
nodemon
with a
.ts
file:
nodemon app.ts
Past versions:
I faced the same issue in my setup until I discovered that you can customize the behavior of nodemon
using its API.
For instance, in the latest version of nodemon
:
nodemon --watch "src/**" --ext "ts,json" --ignore "src/**/*.spec.ts" --exec "ts-node src/index.ts"
Alternatively, create a nodemon.json
file with these settings:
{
"watch": ["src"],
"ext": "ts,json",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/index.ts" // or "npx ts-node src/index.ts"
}
Then simply run nodemon
without any arguments.
By following this approach, you can live-reload a ts-node
process hassle-free, without concerning yourself with the details of the implementation.
For older versions of nodemon
:
nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec 'ts-node' src/index.ts
Or take it up a notch: move nodemon's configuration to a separate nodemon.json
file with these specifications, and then just launch nodemon
, as suggested by Sandokan:
{
"watch": ["src/**/*.ts"],
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./index.ts"
}