<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gonzalo López</title>
    <description>The latest articles on DEV Community by Gonzalo López (@goloti).</description>
    <link>https://dev.to/goloti</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F386914%2Ff1b5d063-c3e7-4804-9616-8ff0b243e3f0.png</url>
      <title>DEV Community: Gonzalo López</title>
      <link>https://dev.to/goloti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/goloti"/>
    <language>en</language>
    <item>
      <title>Deno live reload server</title>
      <dc:creator>Gonzalo López</dc:creator>
      <pubDate>Sun, 24 May 2020 21:31:57 +0000</pubDate>
      <link>https://dev.to/goloti/deno-live-reload-server-mnm</link>
      <guid>https://dev.to/goloti/deno-live-reload-server-mnm</guid>
      <description>&lt;p&gt;Hey! We just started our first steps at deno. We already forgot to run our deno script with the &lt;code&gt;--allow-net&lt;/code&gt; flag. We also exclaim WTF! after check that &lt;code&gt;for await&lt;/code&gt; loop or that those remote dependencies works. And, maybe, we have been wondering how our life could be if we would have meet a native standard library before.&lt;/p&gt;

&lt;p&gt;But now, we finally got a running hello world script that could looks similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Server&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://deno.land/std/http/server.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:8000/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;respond&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Hello World!!`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nice! We are the brontosaurus of code, the triceratops of security flags, the std-lib t-rex. But that message is so standard. Lets change it a bit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;respond&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Welcome to my Deno application`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now refresh the browser. Same response... Oh! Probably we forgot to save the file... Nope. Could it mean that the server didn't reload the code? Let's check it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Stop the server. &lt;/li&gt;
&lt;li&gt;Forget the &lt;code&gt;--allow-net&lt;/code&gt; flag (again).&lt;/li&gt;
&lt;li&gt;Rerun the script with the flag.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Well, that's it! Here we got our changes. And now what? Will we have to restart servers each time we make a change? Does not deno have a live reload? &lt;/p&gt;

&lt;p&gt;Fortunately, as allways, someone has faced the problem before us. And also has thought about a solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  DENON
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://deno.land/x/denon" rel="noopener noreferrer"&gt;Denon&lt;/a&gt; is a utility that will monitor for any changes in source files and automatically restart the server.&lt;/p&gt;

&lt;p&gt;If you have worked with node before, you probably know nodemon. Well, here's the deno implementation. So let's follow the &lt;a href="https://deno.land/x/denon/README.md" rel="noopener noreferrer"&gt;read me&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;It is veeeery simple. First, ensure we have at least the &lt;code&gt;1.0.1&lt;/code&gt; version of deno. We can check our version with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;deno &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If our version is older, we can upgrade it using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;deno upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once we got the correct version, we are ready to install it. We will use the &lt;a href="https://deno.land/manual/tools/script_installer" rel="noopener noreferrer"&gt;script installer tool&lt;/a&gt;. Here is the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;deno &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--allow-read&lt;/span&gt; &lt;span class="nt"&gt;--allow-run&lt;/span&gt; &lt;span class="nt"&gt;--allow-write&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nt"&gt;--unstable&lt;/span&gt;
https://deno.land/x/denon/denon.ts 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;It seems that each deno command requires allow permissions explicitly. It also requires the explicit &lt;code&gt;--unstable&lt;/code&gt; flag because it uses some &lt;code&gt;std-lib&lt;/code&gt; features (still in beta). I like it. You have to know what are you doing. Perfect. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ensure that installation has been successfully by checking version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;denon &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thats all. We are ready for watch live code. &lt;code&gt;denon&lt;/code&gt; command is just a wrapper, so we have to execute our script as before but using &lt;code&gt;denon&lt;/code&gt; instead of &lt;code&gt;deno&lt;/code&gt; as command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;denon index.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just kidding 😁. Remember that deno requires explicit permissions for everything!!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;denon run &lt;span class="nt"&gt;--allow-net&lt;/span&gt; .&lt;span class="se"&gt;\i&lt;/span&gt;ndex.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will see how the code is reloaded after save a file:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0sqvvs1ufc5kxz17hzo9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0sqvvs1ufc5kxz17hzo9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thats all folks. I hope you could find this usefull!&lt;/p&gt;

</description>
      <category>deno</category>
      <category>livereload</category>
      <category>denon</category>
    </item>
  </channel>
</rss>
