DEV Community

Cover image for How to set up Nodemon & Sucrase
Antoniel Magalhães
Antoniel Magalhães

Posted on

How to set up Nodemon & Sucrase

What is Sucrase?

Sucrase let us develop Node app in ES6,is an alternative to Babel that allows super-fast development builds. If it fits your use case, hopefully, Sucrase can speed up your development experience!

What is Nodemon?

Nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.

Getting Start

First you need to install the packages as development dependencies,

yarn add --dev sucrase 
yarn add --dev nodemon
# Or 
npm install --save-dev sucrase
npm install --save-dev nodemon
Enter fullscreen mode Exit fullscreen mode

After setting the packages as project dependencies, if we try to use the features of Sucrase like this:

node index.js
#Or
nodemon index.js
Enter fullscreen mode Exit fullscreen mode

You will encounter an error because to compile with sucrase, is necessary use sucrase-node instead node, on use nodemon node is called every time some file change in a directory, so how we set to nodemon use sucrase-node instead node?

Nodemon + Sucrase

To set Nodemon to use sucrase we need to create a file nodemon.json in our '/' project, with the following code:

{
  "execMap":{
    "js": "node -r sucrase/register"
  }
}
Enter fullscreen mode Exit fullscreen mode

Once we create this file every time nodemon executes a js file, it will be compiled by sucrase before run the code.

References

https://www.npmjs.com/package/sucrase

https://www.npmjs.com/package/nodemon

Top comments (0)