<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hasitha Madusanka on Medium]]></title>
        <description><![CDATA[Stories by Hasitha Madusanka on Medium]]></description>
        <link>https://medium.com/@hasithaAlex?source=rss-d6f4038a9fe0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*do8_2Iu0jeZjB5j1N_rHZw.png</url>
            <title>Stories by Hasitha Madusanka on Medium</title>
            <link>https://medium.com/@hasithaAlex?source=rss-d6f4038a9fe0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 14:34:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hasithaAlex/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Node Module System]]></title>
            <link>https://medium.com/@hasithaAlex/node-module-system-da84d3096dd9?source=rss-d6f4038a9fe0------2</link>
            <guid isPermaLink="false">https://medium.com/p/da84d3096dd9</guid>
            <category><![CDATA[node-modules]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Hasitha Madusanka]]></dc:creator>
            <pubDate>Sun, 24 Jun 2018 03:12:41 GMT</pubDate>
            <atom:updated>2018-06-24T03:14:24.488Z</atom:updated>
            <content:encoded><![CDATA[<p>node Modules examples : os, fs, events, http</p><p><strong>What Modules are?</strong></p><ul><li>In Node we don’t have window object instead we have another object called <em>global.</em> All the inbuilt functions can be accessed by via <em>global </em>object.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*41XncAGC8x8Y20HvlQts1g.png" /><figcaption>figure 01</figcaption></figure><ul><li><strong>Not like client side JavaScript</strong> the variable define in scope using var not gonna added to <em>global</em> object. (output gonna be undefined). They are only scope to in this file so they are not gonna available outside of this file. This is because of Node modular system.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*LCfT1-JdZX8JkXkTmmKk1A.png" /><figcaption>figure 02</figcaption></figure><ul><li>Why Node things(functions and variables) not added to global scope like client side JavaScript. Because client side JavaScript behavior has a problem which is each and every function add to global scope and cause to override functions and variables that has same names. In order to build reliable and maintainable applications we should avoid defining variables and function in the global scope. Instead we need modularity.</li></ul><p><strong>Why we need Modules?</strong></p><ul><li>We need to create small building blocks or modules so two functions or variables with same name won’t override each other. Every file in node application as considers as module. The variables and functions define in that file or that module is scoped to that file.</li><li>In OOP terms we say they are <em>private.</em> If you want to access variable define module from outside from a module you need to explicitly export it and make it public.</li><li>In Node module has at least one file or one module which we called main module.</li></ul><p><strong>How Modules works?</strong></p><ul><li>What is in node <em>module object. </em>id: Every module has , filename: compete path to that file, loaded: module loaded or not, .. etc. you will gradually familiar with this object.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*m41UH48Rfi-NSpmUaeCVXg.png" /><figcaption>figure 03</figcaption></figure><p><strong>How to create and import modules?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Qcs8xj6hSklXu6Teo6xnvQ.png" /><figcaption>figure 04</figcaption></figure><ul><li>figure 04 shows how to create module and how to import it. import it to other module it get single object using it’s variable you can access functions. This is how modules can work in Node.</li><li>better we can store import objects into constant because we can accidentally override the value of logger from another value.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da84d3096dd9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>