<?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: Md Abdul Momin</title>
    <description>The latest articles on DEV Community by Md Abdul Momin (@momin).</description>
    <link>https://dev.to/momin</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%2F47327%2F0414a88c-bbd8-448f-bf81-3a3dc1845d1d.jpg</url>
      <title>DEV Community: Md Abdul Momin</title>
      <link>https://dev.to/momin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/momin"/>
    <language>en</language>
    <item>
      <title>Deno- JavaScript and TypeScript Runtime</title>
      <dc:creator>Md Abdul Momin</dc:creator>
      <pubDate>Thu, 13 Aug 2020 06:09:17 +0000</pubDate>
      <link>https://dev.to/momin/deno-javascript-and-typescript-runtime-2dbh</link>
      <guid>https://dev.to/momin/deno-javascript-and-typescript-runtime-2dbh</guid>
      <description>&lt;p&gt;&lt;em&gt;photo credit: &lt;a href="https://pexels.com"&gt;https://pexels.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Introduction
&lt;/h4&gt;

&lt;p&gt;Almost two years ago, &lt;a href="https://github.com/ry"&gt;Ryan Dahl&lt;/a&gt;, the creator of Node.js, talked about the ten things he regretted about Node.js. At the same time, he introduced DENO, a prototype of a new, security-first, npm-less JavaScript, and typescript runtime. Recently &lt;a href="https://deno.land"&gt;DENO 1.0&lt;/a&gt; released.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Deno?
&lt;/h4&gt;

&lt;p&gt;We know that javascript is the battle field-tested Dynamic language for the web, and we cannot imagine the web industry without JavaScript. Through standard organizations like ECMA international, the language has been evolving day by day. It's easy to explain why is the natural choice for dynamic language tooling, whether in a browser environment or as standalone processes.&lt;/p&gt;

&lt;p&gt;NodeJS: open-source, cross-platform, JavaScript runtime environment, invented by the same author almost ten years ago. People have found it useful for web development, tooling, creating a server, and many other use cases. In the presentation, ten things regret nodejs that are discussed in more detail.&lt;/p&gt;

&lt;p&gt;Now the changing JavaScript world, and new additions like TypeScript, building Node projects can become a problematic effort, involving managing build systems and another heavy-handed tooling that takes away from the fun of dynamic language scripting. Furthermore, the mechanism for linking to external libraries is fundamentally centralized through the NPM repository, which is not in line with the web's ideals.&lt;/p&gt;

&lt;h4&gt;
  
  
  Deno
&lt;/h4&gt;

&lt;p&gt;Deno is a new runtime for executing JavaScript and TypeScript outside of the web browser.&lt;br&gt;
Deno attempts to provide a complete solution for quickly scripting complex functionality.&lt;br&gt;
[code]&lt;/p&gt;
&lt;h4&gt;
  
  
  Will it replace NodeJS?
&lt;/h4&gt;

&lt;p&gt;NodeJs is a battle field-tested platform and incredibly well supported that is going to evolve day by day.&lt;/p&gt;
&lt;h4&gt;
  
  
  Typescript Support
&lt;/h4&gt;

&lt;p&gt;Under the hood, deno built on V8, Rust, and Tokio. The &lt;code&gt;rusty_v8&lt;/code&gt; crate provides high-quality Rust bindings to &lt;code&gt;V8's C++ API&lt;/code&gt;. So it is easy to explain written in particular TypeScript means we get a lot of the benefits of TypeScript even if we might choose to write our code in plain JavaScript. So deno does not require typescript compilation setup, deno do it for automatically.&lt;/p&gt;
&lt;h4&gt;
  
  
  Node Vs. Deno
&lt;/h4&gt;

&lt;p&gt;Both are developed upon chrome V8 engines, and great for developing server-side with JavaScript. Node written in C++, deno written in Rust and typescript. Node has officially package manager called npm, and deno has no package manager, instead of package manager deno call ES module from URLs. Node uses the CommonJS syntax for importing packages, deno uses Es Modules. Deno uses modern ECMA script feature in all its API and standard library, while nodejs use a callback-based standard library. Deno offers a security layer through permission. A Node.js program can access anything the user can access.&lt;/p&gt;
&lt;h4&gt;
  
  
  Install Deno
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Using Homebrew (macOS):&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;brew install deno&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Using Powershell&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;iwr https://deno.land/x/install/install.ps1 -useb | iex&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;testing your installation via &lt;code&gt;deno  --version&lt;/code&gt; to know help text use &lt;code&gt;deno -help&lt;/code&gt; and to upgrade previously installed deno use &lt;code&gt;deno upgrade&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;    deno 1.0.0
    A secure JavaScript and TypeScript runtime

    Docs: https://deno.land/std/manual.md
    Modules: https://deno.land/std/ https://deno.land/x/
    Bugs: https://github.com/denoland/deno/issues

    To start the REPL:
      deno

    To execute a script:
      deno run https://deno.land/std/examples/welcome.ts

    To evaluate code &lt;span class="k"&gt;in &lt;/span&gt;the shell:
      deno &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"console.log(30933 + 404)"&lt;/span&gt;

    USAGE:
        deno &lt;span class="o"&gt;[&lt;/span&gt;OPTIONS] &lt;span class="o"&gt;[&lt;/span&gt;SUBCOMMAND]

    OPTIONS:
        &lt;span class="nt"&gt;-h&lt;/span&gt;, &lt;span class="nt"&gt;--help&lt;/span&gt;                     Prints &lt;span class="nb"&gt;help &lt;/span&gt;information
        &lt;span class="nt"&gt;-L&lt;/span&gt;, &lt;span class="nt"&gt;--log-level&lt;/span&gt; &amp;lt;log-level&amp;gt;    Set log level &lt;span class="o"&gt;[&lt;/span&gt;possible values: debug, info]
        &lt;span class="nt"&gt;-q&lt;/span&gt;, &lt;span class="nt"&gt;--quiet&lt;/span&gt;                    Suppress diagnostic output
        &lt;span class="nt"&gt;-V&lt;/span&gt;, &lt;span class="nt"&gt;--version&lt;/span&gt;                  Prints version information

    SUBCOMMANDS:
        bundle         Bundle module and dependencies into single file
        cache          Cache the dependencies
        completions    Generate shell completions
        doc            Show documentation &lt;span class="k"&gt;for &lt;/span&gt;a module
        &lt;span class="nb"&gt;eval           &lt;/span&gt;Eval script
        &lt;span class="nb"&gt;fmt            &lt;/span&gt;Format &lt;span class="nb"&gt;source &lt;/span&gt;files
        &lt;span class="nb"&gt;help           &lt;/span&gt;Prints this message or the &lt;span class="nb"&gt;help &lt;/span&gt;of the given subcommand&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt;
        info           Show info about cache or info related to &lt;span class="nb"&gt;source &lt;/span&gt;file
        &lt;span class="nb"&gt;install        &lt;/span&gt;Install script as an executable
        repl           Read Eval Print Loop
        run            Run a program given a filename or url to the module
        &lt;span class="nb"&gt;test           &lt;/span&gt;Run tests
        types          Print runtime TypeScript declarations
        upgrade        Upgrade deno executable to given version

    ENVIRONMENT VARIABLES:
        DENO_DIR             Set deno&lt;span class="s1"&gt;'s base directory (defaults to $HOME/.deno)
        DENO_INSTALL_ROOT    Set deno install'&lt;/span&gt;s output directory
                             &lt;span class="o"&gt;(&lt;/span&gt;defaults to &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.deno/bin&lt;span class="o"&gt;)&lt;/span&gt;
        NO_COLOR             Set to disable color
        HTTP_PROXY           Proxy address &lt;span class="k"&gt;for &lt;/span&gt;HTTP requests
                             &lt;span class="o"&gt;(&lt;/span&gt;module downloads, fetch&lt;span class="o"&gt;)&lt;/span&gt;
        HTTPS_PROXY          Same but &lt;span class="k"&gt;for &lt;/span&gt;HTTPS

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Your first Deno app
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Hello World&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is simple example to teach you about fundamental about deno&lt;/p&gt;

&lt;p&gt;&lt;code&gt;deno run https://deno.land/std/examples/welcome.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Making an http request&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Deno&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&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;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&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;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;arrayBuffer&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Deno&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's walk through what this application does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Here we get the first argument passed to the application and store it in the variable url.&lt;/li&gt;
&lt;li&gt;Then we make a request to the url specified, await the response, and store it in a variable named res.&lt;/li&gt;
&lt;li&gt;Then we parse the response body as an ArrayBuffer, await the response, convert it into a Uint8Array and store it in the variable body.&lt;/li&gt;
&lt;li&gt;And we write the contents of the body variable to stdout.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try this following example&lt;br&gt;
&lt;code&gt;deno run https://deno.land/std/examples/curl.ts https://example.com&lt;/code&gt;&lt;br&gt;
  you will see  an error regarding network access. So what was the wrong? We know that Deno is a runtime that is secure by default. This means that we have to need explicitly give programs the permission to do certain privileged actions like network access.&lt;/p&gt;

&lt;p&gt;Try outs again&lt;br&gt;
&lt;code&gt;deno run --allow-net=example.com https://deno.land/std/examples/curl.ts https://example.com&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Simple TCP Server&lt;br&gt;
This is an example of a simple server which accepts connections on port 8080, and returns to the client anything it sends.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;listener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Deno&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&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;8080&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;listening on 0.0.0.0:8080&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;conn&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Deno&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;conn&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;For security reasons, Deno does not allow programs to access the network without explicit permission. To allow accessing the network, use a command-line flag:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;deno run --allow-net https://deno.land/std/examples/echo_server.ts&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
To test it, try sending data to it with netcat:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nv"&gt;$ &lt;/span&gt;nc localhost 8080
   hello world
   hello world
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Like the &lt;code&gt;cat.ts&lt;/code&gt; example, the &lt;code&gt;copy()&lt;/code&gt; function here also does not make unnecessary memory copies. It receives a packet from the kernel and sends back, without further complexity.&lt;/p&gt;

&lt;h4&gt;
  
  
  Resources
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://denoweekly.com/"&gt;Deno Weekly&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://deno.land/manual"&gt;Official Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://discord.gg/deno"&gt;Community Discord Group&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>deno</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Which one is valid ? How can answer 15 for both ?</title>
      <dc:creator>Md Abdul Momin</dc:creator>
      <pubDate>Thu, 01 Mar 2018 05:54:09 +0000</pubDate>
      <link>https://dev.to/momin/which-one-is-valid--how-can-answer-15-for-both---3jcm</link>
      <guid>https://dev.to/momin/which-one-is-valid--how-can-answer-15-for-both---3jcm</guid>
      <description>&lt;h3&gt;
  
  
  01
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function doSomething(a) {
    b = a + doSomethingElse( a * 2 );

    console.log( b * 3 );
}

function doSomethingElse(a) {
    return a - 1;
}

var b;

doSomething( 2 ); // 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  02
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function doSomething(a) {
    function doSomethingElse(a) {
        return a - 1;
    }

    var b;

    b = a + doSomethingElse( a * 2 );

    console.log( b * 3 );
}

doSomething( 2 ); // 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
