TSC Watch, Nodemon and Concurrently
Video Lecture
Description
After creating the tsconfig.json, we can now compile and watch for changes using
1 | tsc -p src/server/ -w |
We can host using
1 | node dist/server/server.js |
The nodejs doesn't restart when there are changes to the files, so we can install nodemon
1 | npm install --save-dev nodemon |
Now host the server using
1 | npx nodemon dist/server/server.js |
Note
Note the use of the npx
before the nodemon
command above. Since nodemon was installed with the --save-dev
option, you cannot call it directly from the command line unless it is also installed globally. Leave off the --save-dev
option if you want to install it globally. Prefixing the nodemon
command with npx
, as I do above, allows you to bypass the need to install it globally.
Rather than typing these compile and nodemon commands all the time, we can create a single command to start both processes at the same time.
Install concurrently
1 | npm install --save-dev concurrently |
Add this line to the package.json scripts section
1 | "dev" : "concurrently -k \"tsc -p ./src/server -w\" \"nodemon ./dist/server/server.js\"", |
And start using
1 | npm run dev |
Note
Since we are running the nodemon
and concurrently
libs from the new dev
script in the projects package.json
, it is unnecessary to also have nodemon
and concurrently
installed globally if you don't really want to.