Nodemon for Deno
Update: As of Deno v1.4, there is a built in watch mode that you can enable with the
--watch flag. Read more about that here.
Nodemon, or as I read it in my head Nodémon!, is a utility for restarting Node.js processes when the source changes. It’s is the first dev dependency I add when working in Node, because it is so handy!
Enter denon, the “replacement” for Nodemon in Deno land. As long as you’re using
deno@^1.0.1, you can get all the goodness of automattic restarting with denon.
You can install denon with Deno’s
deno install --allow-read --allow-run --allow-write --allow-net -f --unstable https://email@example.com/denon.ts
That command installs denon version
2.2.0, so reference the documentation for the most up-to-date instructions.
Once you have denon installed, you can use it as a straight replacement for all
# With Deno
deno run --allow-net https://deno.land/std/examples/echo_server.ts
# With denon
denon run --allow-net https://deno.land/std/examples/echo_server.ts
This is the same behavior as
node/nodemon. But running external code doesn’t really illustrate the value of denon.
To see it in action, copy
echo_server.ts locally and then run with denon:
denon run --allow-net echo_server.ts
Now when you make any changes to the source, you will see denon automatically restart the server.
My favorite feature of denon is its configuration file:
denon.json. With it, you get some of the “scripts” features of Node.js’s
package.json that are currently missing in Deno.
To create a configuration file, you can call denon with the
This will create a
denon.json file where you can include scripts with commands, permissions, and environment variables.
We can create a “start” script for the
echo_server.ts like so:
"cmd": "deno run echo_server.ts",
"desc": "Start echo_server in watch mode",
"allow": ["env", "net"],
Our “start” script has a command, description, permissions to allow, and an environment variable
PORT that we are passing to our server.
To run the script, type:
And you’re off to the races! I love the ability to start a Deno process without typing all those permissions. :chefs-kiss:
The denon documentation lists the full feature set and includes a bunch of helpful examples. Make sure to check that out when setting up denon on your next Deno project.