At the moment, to see the final product, we have to run the build
script after each time we modify our source code. While this is fine, it can be annoying and a time-waster. nodemon
is a tool that monitors for changes in our code and automatically restarts the node
process when a change is detected. This can speed up development and testing, as we no longer need to run the build
and serve
scripts manually. Furthermore, the API served from our machine will always be the most up-to-date version.
First, let's install nodemon
:
$ yarn add nodemon --dev
Next, add a watch
script that uses nodemon
instead of node
:
"scripts": { "build": "rimraf dist && babel src -d dist", "serve": "yarn run build && node dist/index.js", "test": "echo \"Error: no test specified\" && exit 1", "watch": "nodemon -w src --exec yarn run serve" },
This command instructs nodemon to watch for file changes in the src
directory and, whenever one is detected, to...