<?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: Bryant Son</title>
    <description>The latest articles on DEV Community by Bryant Son (@bryantson).</description>
    <link>https://dev.to/bryantson</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%2F908658%2Ffa163c6e-8c54-4068-929c-a4f9454e7d2e.jpg</url>
      <title>DEV Community: Bryant Son</title>
      <link>https://dev.to/bryantson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bryantson"/>
    <language>en</language>
    <item>
      <title>How to learn Deno as an alternative to Node.js</title>
      <dc:creator>Bryant Son</dc:creator>
      <pubDate>Mon, 03 Oct 2022 13:19:46 +0000</pubDate>
      <link>https://dev.to/bryantson/how-to-learn-deno-as-an-alternative-to-nodejs-4dcg</link>
      <guid>https://dev.to/bryantson/how-to-learn-deno-as-an-alternative-to-nodejs-4dcg</guid>
      <description>&lt;p&gt;&lt;a href="https://deno.land/"&gt;&lt;strong&gt;Deno&lt;/strong&gt;&lt;/a&gt; is a simple, modern, and secure runtime for JavaScript and TypeScript. It uses the JavaScript and WebAssembly engine &lt;a href="https://v8.dev/"&gt;V8&lt;/a&gt; and is built in &lt;a href="https://opensource.com/article/20/12/rust"&gt;Rust&lt;/a&gt;. The project, open source under an MIT License, was created by &lt;a href="https://en.wikipedia.org/wiki/Ryan_Dahl"&gt; &lt;strong&gt;Ryan Dahl&lt;/strong&gt;&lt;/a&gt;, the developer who created Node.js.&lt;/p&gt;

&lt;p&gt;You can watch all of these videos and instructions in following tutorials:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vSJn8LB_h8k"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/sRxDGMow7j8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/BAAWtWkijSM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/rUiSsE2hJWc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/denoland/deno/blob/v1.5.4/docs/introduction.md"&gt;Deno's GitHub repository&lt;/a&gt; outlines its goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Only ship a single executable (deno)&lt;/li&gt;
&lt;li&gt;Provide secure defaults&lt;/li&gt;
&lt;li&gt;Unless specifically allowed, scripts can't access files, the environment, or the network.&lt;/li&gt;
&lt;li&gt;Browser compatible: The subset of Deno programs which are written completely in JavaScript and do not use the global Deno namespace (or feature test for it), ought to also be able to be run in a modern web browser without change.&lt;/li&gt;
&lt;li&gt;Provide built-in tooling like unit testing, code formatting, and linting to improve developer experience.&lt;/li&gt;
&lt;li&gt;Does not leak V8 concepts into user land.&lt;/li&gt;
&lt;li&gt;Be able to serve HTTP efficiently&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The repo also describes how Deno is different from NodeJS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deno does not use npm.&lt;/li&gt;
&lt;li&gt;It uses modules referenced as URLs or file paths.&lt;/li&gt;
&lt;li&gt;Deno does not use package.json in its module resolution algorithm.&lt;/li&gt;
&lt;li&gt;All async actions in Deno return a promise. Thus Deno provides different APIs than Node.&lt;/li&gt;
&lt;li&gt;Deno requires explicit permissions for file, network, and environment access.&lt;/li&gt;
&lt;li&gt;Deno always dies on uncaught errors.&lt;/li&gt;
&lt;li&gt;Uses "ES Modules" and does not support require(). Third party modules are imported via URLs:
&lt;/li&gt;
&lt;/ul&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="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;log&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@$STD_VERSION/log/mod.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install Deno
&lt;/h2&gt;

&lt;p&gt;Deno's website has &lt;a href="https://deno.land/#installation"&gt;installation instructions&lt;/a&gt; for various operating systems, and its complete source code is available in its &lt;a href="https://github.com/denoland/deno"&gt;GitHub repo&lt;/a&gt;. I run macOS, so I can install Deno with HomeBrew:&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;brew &lt;span class="nb"&gt;install &lt;/span&gt;deno
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Linux, you can download, read, and then run the install script from Deno's server:&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;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://deno.land/x/install/install.sh
&lt;span class="nv"&gt;$ &lt;/span&gt;sh ./install.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run Deno
&lt;/h2&gt;

&lt;p&gt;After installing Deno, the easiest way to run it is:&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 run https://deno.land/std/examples/welcome.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you explore the &lt;a href="https://deno.land/std/examples/welcome.ts"&gt;welcome example&lt;/a&gt;, you should see a single line that prints "Welcome to Deno" with a dinosaur icon. Here is slightly a more complicated version that also can be found on the website:&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="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://deno.land/std@0.83.0/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;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;req&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&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;Save the file with a .tx extension. Run it 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 run &lt;span class="nt"&gt;--allow-net&lt;/span&gt; &amp;lt;name-of-your-first-deno-file.ts&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;--allow-net&lt;/em&gt; flag might not be necessary, but you can use it if you see an error like error: _Uncaught PermissionDenied: network access to "0.0.0.0:8000.&lt;br&gt;
_&lt;br&gt;
Now, open a browser and visit localhost:8080. It should print "Hello, World!"&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
