How do I execute typescript watch and running server at the same time?
My idea is merge the commands as tsc -w & node app.js but I can't work the two commands at the same time. How do I do
You have a few options. Simplest is to use ts-node-dev
: https://github.com/whitecolor/ts-node-dev
Step 1
install concurrently
, use npm
or yarn
yarn add concurrently -D
Step 2
create a script with this command
"scripts": { "run": "tsc && concurrently \"tsc -w\" \"nodemon dist/app.js\"",}
run tsc first so that your directory has something at the time of running node
And with that you will have running your Typescript application 🚀
Another option can be to use nodemon:
tsc -w & nodemon app.js
Since Typescript 3.4 the compilation is faster because you can use the incremental
compiler option and they keep improving (including interesting changes for large projects in 3.8).
Update:
I also moved to use concurrently as HerberthObregon says in his answer