Nodemon Like Reloader 🔄 in Deno (Denon)

haarisiqubal

Haaris Iqubal

Posted on May 28, 2020

Nodemon Like Reloader 🔄 in Deno (Denon)

It might be frustrating to always close your Deno server and restart it again. As Deno doesn't provide "Hot Reload" out of the box but still there is a way to do it, so no more closing your server and restart it again or banging your head to a desk 😅.

For the sake of this example we gonna make little Deno application into "app.ts" file


import { serve } from "https://deno.land/std@0.52.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
 req.respond({ body: "Hello World\n" });
}

After saving the code you need to install Denon. Denon is the deno replacement for nodemon providing a feature-packed and easy to use experience. You need to upgrade Deno v1.0.2 to install the Denon simple type the following command.


$ deno upgrade

Now you just need to write the following command into your Terminal or PowerShell and you ready to go.


$ deno install --allow-read --allow-run --allow-write -f --unstable https://deno.land/x/denon/denon.ts

Denon uses unstable features of the stdlib, as a result the flag - unstable currently required for the installation. You can see various other options Denon has provided by simply writing "denon -h" or "denon- help". For running our app.ts file we need to write denon run then we have to pass the flag so that our app will only pass those options require by the user then we need to type the file name.


$ denon run -allow-env -allow-net app.ts

Now enjoy the feature of host reload on the fly whenever you change your file. Just try to change the body msg to "Deno is amazing" and you are done.

You can also follow our video tutorial also on youtube on Recoding .

💖 💪 🙅 🚩
haarisiqubal
Haaris Iqubal

Posted on May 28, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related