<?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: daichitt</title>
    <description>The latest articles on DEV Community by daichitt (@daichitt).</description>
    <link>https://dev.to/daichitt</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%2F2031400%2F4756642a-ad73-44e3-aa7f-c201fa837d6d.jpeg</url>
      <title>DEV Community: daichitt</title>
      <link>https://dev.to/daichitt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/daichitt"/>
    <language>en</language>
    <item>
      <title>CommonJS and ES Modules</title>
      <dc:creator>daichitt</dc:creator>
      <pubDate>Mon, 16 Jun 2025 08:42:33 +0000</pubDate>
      <link>https://dev.to/daichitt/commonjs-and-es-modules-2pfk</link>
      <guid>https://dev.to/daichitt/commonjs-and-es-modules-2pfk</guid>
      <description>&lt;p&gt;In Node.js, there are two distinct module management systems: &lt;strong&gt;CommonJS&lt;/strong&gt; and &lt;strong&gt;ES Modules (ECMAScript Modules)&lt;/strong&gt;. The difference between the two code snippets you provided lies in these module systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. CommonJS (&lt;code&gt;const express = require('express')&lt;/code&gt;)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CommonJS&lt;/strong&gt; is the default module management system in Node.js.&lt;/li&gt;
&lt;li&gt;It uses &lt;code&gt;require()&lt;/code&gt; to import modules.&lt;/li&gt;
&lt;li&gt;When a file has a &lt;code&gt;.js&lt;/code&gt; extension, Node.js treats it as a CommonJS module by default.
&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&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;ul&gt;
&lt;li&gt;This format has been the standard way of writing modules in the Node.js environment for a long time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. ES Modules (&lt;code&gt;import express from 'express'&lt;/code&gt;)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ES Modules (ECMAScript Modules)&lt;/strong&gt; is a module system based on the latest JavaScript specification.&lt;/li&gt;
&lt;li&gt;It uses &lt;code&gt;import&lt;/code&gt; to import modules.&lt;/li&gt;
&lt;li&gt;To use ES Modules, you typically use the &lt;code&gt;.mjs&lt;/code&gt; file extension, or you need to set &lt;code&gt;"type": "module"&lt;/code&gt; in your &lt;code&gt;package.json&lt;/code&gt; file.
&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="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&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;ul&gt;
&lt;li&gt;ES Modules are the latest JavaScript standard and are supported in browsers and newer Node.js versions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Differences
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;require()&lt;/code&gt;&lt;/strong&gt; is used in &lt;strong&gt;CommonJS&lt;/strong&gt;, while &lt;strong&gt;&lt;code&gt;import&lt;/code&gt;&lt;/strong&gt; is used in &lt;strong&gt;ES Modules&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using ES Modules requires configuration (e.g., file extension or &lt;code&gt;package.json&lt;/code&gt; settings).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CommonJS&lt;/strong&gt; is an older, widely used module system that is still common in most Node.js projects, but &lt;strong&gt;ES Modules&lt;/strong&gt; are gradually gaining popularity as the new standard.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Which system you should use depends on your project's requirements and compatibility needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sample package.json
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sample PJ"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"private"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;ES&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Modules&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vite"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tsc; vite build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"lint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"preview"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vite preview"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"deploy"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run build &amp;amp;&amp;amp; firebase deploy --only hosting"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;   
        &lt;/span&gt;&lt;span class="nl"&gt;"react"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^19.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"devDependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"@types/react"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^19.0.4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>esmodules</category>
      <category>javascript</category>
      <category>esmodule</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Promise JavaScript</title>
      <dc:creator>daichitt</dc:creator>
      <pubDate>Mon, 16 Jun 2025 08:36:48 +0000</pubDate>
      <link>https://dev.to/daichitt/promise-javascript-59ne</link>
      <guid>https://dev.to/daichitt/promise-javascript-59ne</guid>
      <description>&lt;h2&gt;
  
  
  Terminology
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;CallStack&lt;/li&gt;
&lt;li&gt;Task queue&lt;/li&gt;
&lt;li&gt;Promise&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Execution Order
&lt;/h2&gt;

&lt;p&gt;I had a misunderstanding about the execution order, so I'm summarizing it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;code&gt;orderExecutor&lt;/code&gt; is called and enters the &lt;strong&gt;Call Stack&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;orderExecutor&lt;/code&gt; exits the &lt;strong&gt;Call Stack&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;then&lt;/code&gt; enters the &lt;strong&gt;Task Queue&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;console.log('2')&lt;/code&gt; is called and enters the &lt;strong&gt;Call Stack&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;console.log('2')&lt;/code&gt; exits the &lt;strong&gt;Call Stack&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt; Since the &lt;strong&gt;Call Stack&lt;/strong&gt; is empty, &lt;code&gt;then&lt;/code&gt; moves from the &lt;strong&gt;Task Queue&lt;/strong&gt; into the &lt;strong&gt;Call Stack&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;then&lt;/code&gt; is executed.&lt;/li&gt;
&lt;/ol&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function orderExecutor(resolve, reject) {
    console.log('1'); // 1
    resolve('3');
}
let orderPizza = new Promise(orderExecutor);
orderPizza.then(function (value) {
    console.log(value); // 3
});
console.log('2'); // 2

// 1, 2, 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide/In_depth" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide/In_depth&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=eiC58R16hb8&amp;amp;t=518s" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=eiC58R16hb8&amp;amp;t=518s&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Abstract Syntax Tree with Javascript</title>
      <dc:creator>daichitt</dc:creator>
      <pubDate>Mon, 16 Jun 2025 08:25:43 +0000</pubDate>
      <link>https://dev.to/daichitt/sadsa-5chg</link>
      <guid>https://dev.to/daichitt/sadsa-5chg</guid>
      <description>&lt;h2&gt;
  
  
  Javascript sample code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const war = 5; // VariableDeclarator

 function triple(number){  // FunctionDeclaration
   return 3 * war; 
 }

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Json out put
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "type": "Program",
  "start": 0,
  "end": 59,
  "body": [
    {
      "type": "VariableDeclaration",
      "start": 0,
      "end": 14,
      "declarations": [
        {
          "type": "VariableDeclarator",
          "start": 6,
          "end": 13,
          "id": {
            "type": "Identifier",
            "start": 6,
            "end": 9,
            "name": "war"
          },
          "init": {
            "type": "Literal",
            "start": 12,
            "end": 13,
            "value": 5,
            "raw": "5"
          }
        }
      ],
      "kind": "const"
    },
    {
      "type": "FunctionDeclaration",
      "start": 16,
      "end": 59,
      "id": {
        "type": "Identifier",
        "start": 25,
        "end": 31,
        "name": "triple"
      },
      "expression": false,
      "generator": false,
      "async": false,
      "params": [
        {
          "type": "Identifier",
          "start": 32,
          "end": 38,
          "name": "number"
        }
      ],
      "body": {
        "type": "BlockStatement",
        "start": 39,
        "end": 59,
        "body": [
          {
            "type": "ReturnStatement",
            "start": 42,
            "end": 57,
            "argument": {
              "type": "BinaryExpression",
              "start": 49,
              "end": 56,
              "left": {
                "type": "Literal",
                "start": 49,
                "end": 50,
                "value": 3,
                "raw": "3"
              },
              "operator": "*",
              "right": {
                "type": "Identifier",
                "start": 53,
                "end": 56,
                "name": "war"
              }
            }
          }
        ]
      }
    }
  ],
  "sourceType": "module"
}

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffhd77f1fsapba2skwjqf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffhd77f1fsapba2skwjqf.png" alt="Screenshot 2025-06-14 at 14.17.49.png" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Javascript sample code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://astexplorer.net/" rel="noopener noreferrer"&gt;https://astexplorer.net/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=N5hczoxUzMU&amp;amp;list=LL&amp;amp;index=4&amp;amp;t=32s" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=N5hczoxUzMU&amp;amp;list=LL&amp;amp;index=4&amp;amp;t=32s&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/abstract-syntax-tree" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/abstract-syntax-tree&lt;/a&gt;&lt;/p&gt;

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