How to setup babel-watch in nodejs project

How to setup babel-watch in nodejs project

Do you want your application to automatically restart itself whenever you make a new change?

After a long time of using babel-node with nodemon it is time to level-up in this game. No more listing a list of directories to watch/detect or worrying about the performance of your startup time.

Babel-watch is a development tool that observes the changes within your node project files and automatically restarts your application.

Installation

It is a development tool means it should be installed under devDependencies. To install a package in the dev dependencies you need to use one of these flags alongside the target package.

--save-dev, --dev, or -D

npm i -D babel-watch

or

yarn add --dev babel-watch

After installing, update your scripts in package.json file.

 "scripts": {
    "dev": "babel-watch src/app.js"
  },

Your package.json should look at least like this. carine-semwaga-babel-watch-setup-package-json.png

Then, run your server.

npm run dev

babel-watch-setup-run-server-carine-hashnode.png