<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Arash Arora - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Arash Arora - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 24 May 2026 16:30:00 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/arasharora/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Get Started with Node.js – Beginner's Guide to Node ]]>
                </title>
                <description>
                    <![CDATA[ By Arash Arora Node.js is a JavaScript runtime that extends its capability to the server-side. It is built on Chrome’s V8 JavaScript Engine. Node is an event-driven, non-blocking IO model. This means it's asynchronous, and doesn't block itself for on... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/introduction-to-nodejs/</link>
                <guid isPermaLink="false">66d45d98c7632f8bfbf1e3d1</guid>
                
                    <category>
                        <![CDATA[ beginner ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ node ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Node.js ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Arash Arora ]]>
                </dc:creator>
                <pubDate>Mon, 11 Jul 2022 21:31:18 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/07/1200px-Node.js_logo.svg.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Arash Arora</p>
<p>Node.js is a JavaScript runtime that extends its capability to the server-side. It is built on Chrome’s V8 JavaScript Engine.</p>
<p>Node is an event-driven, non-blocking IO model. This means it's asynchronous, and doesn't block itself for one request (but rather immediately moves to the next request). This makes Node extraordinarily fast and efficient.</p>
<p>By event-driven, it means that as soon as Node starts it initiates all the variables and functions and waits for an event to occur.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/image-195.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>NPM stands for Node Package Manager which help you manage your packages for Node. NPX stands for Node Package Execute, and it can execute any npm package without even installing it.</p>
<p>To download npm head to <a target="_blank" href="https://nodejs.org/en/download/">https://nodejs.org/en/download/</a>.</p>
<h2 id="heading-how-to-write-your-first-nodejs-program-hello-world">How to Write Your First Node.js Program (Hello World)</h2>
<p>Create a file called hello_world.js in your project folder</p>
<p>Then open the file in your code editor like VS Code. Type the code <code>console.log(“Hello World”);</code> in your editor.</p>
<p>Open the terminal, and navigate to the file location.</p>
<p>Now type <code>node hello_world.js</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/image-196.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-import-node-core-modules">How to Import Node Core Modules</h2>
<p>So let’s start with the very basic package, that is <strong>fs (file system)</strong>. You use it to create, read, and modify files.</p>
<p>To import the fs module, type this command: <code>const fs = require(“fs”);</code>.</p>
<p>Now to use any function of this module, you can refer to the <a target="_blank" href="https://nodejs.org/docs/latest-v17.x/api/fs.html#file-system">docs</a>.</p>
<p>To create a file, we can use <code>fs.writeFileSync(filename, content);</code>.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(“fs”);
fs.writeFileSync(“file.txt”, “Hi there..”);
</code></pre>
<p><img src="https://miro.medium.com/max/446/1*KzqmGo9SE7R3XPYOS-3LXg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To append anything in the same file we can use this:</p>
<pre><code class="lang-js">fs.appendFileSync(filename, content);.
</code></pre>
<p><img src="https://miro.medium.com/max/842/1*dOqUqcuJ5a5vl_BQ_E0dSg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-install-npm-packages">How to Install NPM Packages</h2>
<p>Now we will use a very basic npm package called <strong>superheroes</strong> (which is a list of random superheroes) to help you understand how npm works.</p>
<p>To install any npm package, we can use this command in the cmd:</p>
<pre><code class="lang-plaintext">npm install superheroes
</code></pre>
<p>Now to import the installed package type <code>const sh = require(“superheroes”);</code>.</p>
<p>To display the name of a random superhero, use this command:</p>
<pre><code class="lang-js"><span class="hljs-built_in">console</span>.log(sh.random());.
</code></pre>
<p><img src="https://miro.medium.com/max/1400/1*WfHNl2GDgyXBEwfV6oV0GQ.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Let’s try another package. Now we’ll install one of the most used npm packages called <strong>“chalk” —</strong> it styles text strings in the terminal.</p>
<p>To install the chalk package (we will install version 2.4.2 as it allows us to import the package using the <strong>require</strong> method), type the following command:</p>
<pre><code class="lang-js">npm install chalk@<span class="hljs-number">2.4</span><span class="hljs-number">.2</span>
</code></pre>
<p>Now to style the text string, use this command to pick the color of the string:</p>
<pre><code class="lang-js">chalk.color(text)
</code></pre>
<p><img src="https://miro.medium.com/max/1400/1*AQ5TX0vxzPn5N0lzrSBbJw.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You can read more about the <a target="_blank" href="https://www.npmjs.com/package/chalk">chalk package here</a>.</p>
<h2 id="heading-how-to-initiate-npm-in-our-program">How to Initiate NPM in Our Program</h2>
<p>To initiate NPM in our program, we can use the following command:</p>
<pre><code class="lang-js">npm init
</code></pre>
<p>Then press enter or answer the questions accordingly.</p>
<p><img src="https://miro.medium.com/max/1400/1*G_SVRqNdjuuWssQANvZgbw.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Or you can directly use the command <code>npm init -y</code> (same as pressing enter to all the questions).</p>
<p><img src="https://miro.medium.com/max/1400/1*CafNbhzEhvGAayNHnpb29A.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This will result in the creation of the <strong>package.json</strong> file:</p>
<p><img src="https://miro.medium.com/max/1400/1*hYaMdTgcLdABQ1qqjQdpRQ.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-so-what-is-packagejson">So, what is package.json?</h3>
<p>package.json is the heart of any Nodejs project. It maintains a record of all the dependencies (NPM packages) and contains the metadata of every project.</p>
<p>If someone else downloads the project, this file will help them install all the dependencies required to run the program.</p>
<h2 id="heading-how-to-use-momentjs-an-npm-package">How to Use Moment.js — an NPM Package</h2>
<p>This is one of the most used npm packages out there. You can use it to parse and validate dates.</p>
<p>To install the package, run this command:</p>
<pre><code class="lang-js">npm i moment
</code></pre>
<p>Import the package like this:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> moment = <span class="hljs-built_in">require</span>(“moment”);
</code></pre>
<p>To create a Date object to fetch the current date and time (JavaScript method), run this code:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> time = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>();
</code></pre>
<p>Now, to parse or format the date we will use the <strong>moment</strong> package:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> parsedTime = moment(time).format(<span class="hljs-string">"h:mm:ss"</span>);
</code></pre>
<p>Print the parsed time like this:</p>
<pre><code class="lang-js"><span class="hljs-built_in">console</span>.log(parsedTime);
</code></pre>
<p><img src="https://miro.medium.com/max/1400/1*V3hJ24cmTASx9k6Rv83gXg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This is the package.json for this project which includes all the dependency packages — <strong>moment</strong> in this case.</p>
<p><img src="https://miro.medium.com/max/1400/1*kKFpiaEOtsRbxN67do4HDw.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We also have <strong>node_modules</strong> in the project folder. This folder contains all the dependencies our project depends on including moment and other packages that moment depends on.</p>
<p><img src="https://miro.medium.com/max/454/1*-mxxdXnGzLxG98LE2ebMDQ.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>package-lock.json</strong> is another file in our project folder that contains all the information regarding the name, dependencies, version of dependencies, and locked version of the project.</p>
<p>It describes the exact tree that was generated to allow subsequent installs to have the identical tree.</p>
<p><img src="https://miro.medium.com/max/1400/1*b1VMBTQ3HtQtnaHUWGY8iQ.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h1 id="heading-how-to-use-express-js-a-nodejs-framework">How to Use Express JS — a NodeJS Framework</h1>
<p>Express is a Node.js web application framework that offers a comprehensive range of functionality for both web and mobile apps.</p>
<h3 id="heading-how-to-install-express">How to install Express</h3>
<p>To install Express, run this command:</p>
<pre><code class="lang-js">npm install express
</code></pre>
<p>Then you'll need to import Express like this:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">"express"</span>);
</code></pre>
<h3 id="heading-how-to-create-an-express-application">How to create an Express application</h3>
<p>To create an Express app, just run this command:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> app = express()
</code></pre>
<h3 id="heading-how-to-start-a-server-on-port-3000">How to start a server on port 3000</h3>
<pre><code class="lang-js">app.listen(<span class="hljs-number">3000</span>, <span class="hljs-function">() =&gt;</span> { 
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Server running on port 3000"</span>);
}
</code></pre>
<p><img src="https://miro.medium.com/max/1400/1*jD3FvRLcd_j2MuZ0U6_bXw.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now you can open <a target="_blank" href="http://localhost:3000/"><strong>http://localhost:3000</strong></a> to reach your created server</p>
<p><img src="https://miro.medium.com/max/844/1*IMLmUArtV_ctmiAG18TnJg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Okay, so “cannot get /” means that there is no defined route “/” yet.</p>
<p>So to define the “/” route we use <code>app.get()</code> the function.</p>
<p>The <strong>app.get (route, callback function)</strong> function is used to handle all GET requests.</p>
<p>The callback function has two arguments, <strong>req</strong> and <strong>res</strong>, which refer to HTTP requests and the desired response, respectively. The argument names (req, res) are not fixed and can be named anything you want.</p>
<pre><code class="lang-js">app.get(<span class="hljs-string">"/"</span>, <span class="hljs-function">(<span class="hljs-params">req,res</span>) =&gt;</span> { 
    <span class="hljs-comment">// app.get to handle GET requests</span>
    <span class="hljs-comment">// req - http request, res - desired response</span>
    res.send(<span class="hljs-string">"Hello World"</span>); <span class="hljs-comment">// send Hello World to this route</span>
}
</code></pre>
<h2 id="heading-how-to-create-a-hello-world-program-in-express">How to Create a Hello World Program in Express</h2>
<p>In this section we will create the very basic program of Hello World in Express.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">"express"</span>);
<span class="hljs-keyword">const</span> app = express();
app.get(<span class="hljs-string">"/"</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {  
    res.send(<span class="hljs-string">"hello world"</span>);
});
app.listen(<span class="hljs-number">3000</span>, <span class="hljs-function">() =&gt;</span> {  
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Server running on 3000"</span>);
});
</code></pre>
<p>And here's the output</p>
<p><img src="https://miro.medium.com/max/1060/1*uRqmENgESv8cdq-0oSaX8A.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-render-static-files-in-express">How to Render Static Files in Express</h2>
<p>This section introduces us to the concept of static file rendering using Express.</p>
<p>First, you'll need to create a new project folder. Then you'll initialize npm using <code>npm init -y</code>.</p>
<p>Install the Express package <code>npm i express</code> and create a file called app.js.</p>
<p>Then you'll create an app, and listen or start the server on port 3000.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">"express);
const app = express();
app.listen(3000, () =&gt; {  
    console.log("</span>Server running on <span class="hljs-number">3000</span><span class="hljs-string">");
}</span>
</code></pre>
<p>To render static web pages such as HTML, CSS, and JS, create a folder named public in the root directory.</p>
<p>As we’re focusing on only the backend, we will not spend much time on the frontend and will create only an HTML file in the public folder.</p>
<p><img src="https://miro.medium.com/max/1142/1*-OiGmKZaz7GKc3NdNVjZdg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We will now import the <strong>path</strong> module and join the specified paths into one:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(“path”);
</code></pre>
<p>Now to render these files, we have to use the following command:</p>
<pre><code class="lang-js">app.use(express.static(path.join(__dirname, “/public”)));
</code></pre>
<p><strong>__dirname →</strong> returns the current directory</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">"express"</span>);
<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">"path"</span>);
<span class="hljs-keyword">const</span> app = <span class="hljs-keyword">new</span> express();
app.use(express.static(path.join(__dirname, <span class="hljs-string">"/public"</span>)));
app.listen(<span class="hljs-number">3000</span>, <span class="hljs-function">() =&gt;</span> {  
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Server running on 3000"</span>);
});
</code></pre>
<p>And here's the output:</p>
<p><img src="https://miro.medium.com/max/1034/1*2U5Qi3XKOaNF0MjXSTo0tg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-render-dynamic-files-in-express">How to Render Dynamic Files in Express</h2>
<p>In this section we will learn to render dynamic files in which we can use values from an input object.</p>
<p>To render dynamic web pages, there are many templates such as pug, handlebars, ejs, and so on. These templates allow us to inject dynamic data, if conditions, and loops at runtime.</p>
<p>But here we will focus on handlebars.</p>
<p>Install the packages (express and hbs):</p>
<pre><code class="lang-js">npm i hbs express
</code></pre>
<p>Create a file named app.js and import the packages like this:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(“express”);
<span class="hljs-keyword">const</span> hbs = <span class="hljs-built_in">require</span>(“hbs”);
<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(“path”);
</code></pre>
<p>Create an Express app and listen on port 3000:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> app = express();
app.listen(<span class="hljs-number">3000</span>, <span class="hljs-function">(<span class="hljs-params">req,res</span>) =&gt;</span> {  
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Server running on 3000"</span>);
}
</code></pre>
<p>For handlebars to work, we need to set the view engine as hbs.</p>
<pre><code class="lang-js">app.set(“view engine”, “hbs”);
</code></pre>
<p>The view engine enables us to render dynamic webpages using the specified template.</p>
<p>View engine generally looks for the “views” folder in the root folder. But to avoid errors we’ll mention the path of “views” using the following command:</p>
<pre><code class="lang-js">app.set(“views”, path.join(__dirname,“/views”);
</code></pre>
<p>Now create a <strong>views</strong> folder in the root directory. Under that create a file called index.hbs (.hbs is the extension of handlebars) and insert the following HTML code:</p>
<h3 id="heading-indexhbs">index.hbs</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span> 
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Dynamic Rendering<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span> 
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>  
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Dynamic Rendering<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>   
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>{{author}}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span> <span class="hljs-comment">&lt;!--dynamic data recieved from server--&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p><code>{{author}}</code> — it is the syntax to insert dynamic data</p>
<p>Now to render the index.hbs file we’ll create an app.get function to handle the GET request on the route “/” and send the dynamic data <strong>author</strong>.</p>
<pre><code class="lang-js">app.get(<span class="hljs-string">"/"</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> { 
    res.render(<span class="hljs-string">"index"</span>, {    
        <span class="hljs-attr">author</span>: <span class="hljs-string">"Arash Arora"</span>, 
    });
});
</code></pre>
<p><code>res.render</code> is the function to render the view. Here we have to pass two arguments. The first is the name of the file without the extension and the second is the object of local variables, for example <strong>author</strong>.</p>
<h3 id="heading-appjs-file">app.js file</h3>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">"express"</span>);
<span class="hljs-keyword">const</span> hbs = <span class="hljs-built_in">require</span>(<span class="hljs-string">"hbs"</span>);
<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">"path"</span>);
<span class="hljs-keyword">const</span> app = express();
app.set(<span class="hljs-string">"view engine"</span>, <span class="hljs-string">"hbs"</span>);
app.set(<span class="hljs-string">"views"</span>, path.join(__dirname, <span class="hljs-string">"/views"</span>));
app.get(<span class="hljs-string">"/"</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {  
    res.render(<span class="hljs-string">"index"</span>, {    
        <span class="hljs-attr">author</span>: <span class="hljs-string">"Arash Arora"</span>, 
    });
});
app.listen(<span class="hljs-number">3000</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> { 
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Server listening on 3000"</span>);
});
</code></pre>
<h3 id="heading-folder-structure">Folder structure</h3>
<p><img src="https://miro.medium.com/max/502/1*7xz9Fj17mTS5pZhxzf2dvw.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>And here's the output:</p>
<p><img src="https://miro.medium.com/max/824/1*JQt1mgjLTU-LJJ0XS7UH3A.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h1 id="heading-how-to-create-advanced-templates-with-handlebars">How to Create Advanced Templates with Handlebars</h1>
<p>So, this is where we’ll learn about reusable components. Previously, we had to construct identical components for each and every page when it came to headers and footers.</p>
<p>But because there are so many repetitive tasks, advanced templating is the savior. This concept states that we will just make one component that will be used everywhere we need it.</p>
<h3 id="heading-handlebars-introduced-the-concept-of-partials">Handlebars introduced the concept of Partials</h3>
<p>Partials are the regular handlebar files that other templates can call. Partials are a widely used templating concept that is not specific to Handlebars.</p>
<p>To construct templates that are likely to be reused, you can isolate them into their files (a Partial), and then use them in various templates. You can consider partials to be a simple technique for modularizing your templates.</p>
<p>Follow these steps to create partials:</p>
<ul>
<li><p>Initiate npm → <code>npm init -y</code></p>
</li>
<li><p>Install the required packages, Express, and hbs → <code>npm i express hbs</code></p>
</li>
<li><p>Create your folder templates</p>
</li>
<li><p>Create two additional folders within the folder templates: <strong>partials and views</strong></p>
</li>
<li><p>Now create a file <strong>app.js</strong></p>
</li>
</ul>
<p><img src="https://miro.medium.com/max/472/1*98jLDll1IWq-vd8H0ieNCg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The folder Structure should be similar</em></p>
<p>Let’s create two partial files: header.hbs and footer.hbs. And we'll also add two views, index.hbs and about.hbs.</p>
<p><img src="https://miro.medium.com/max/422/1*E32yq-EHCLFfUFzbgIbJJg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-indexhbs-1">index.hbs</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>   
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Advanced Templating<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>  
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>    
        {{&gt;header}} <span class="hljs-comment">&lt;!--include the header component--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I'm a savior<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>    
        {{&gt;footer}} <span class="hljs-comment">&lt;!-- include the footer component --&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h3 id="heading-abouthbs">about.hbs</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>    
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Advanced Templating -- About<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span> 
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>   
        {{&gt;header}}   
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Handlebars<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>    
        {{&gt;footer}} 
    <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h3 id="heading-headerhbs">header.hbs</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Advanced Templating<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span> 
    <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>{{title}}<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span><span class="hljs-comment">&lt;!--dynamic data received from server--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span> 
    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/about"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>
</code></pre>
<h3 id="heading-footerhbs">footer.hbs</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">footer</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Created by {{name}}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span> <span class="hljs-comment">&lt;!--name -&gt; dynamic data --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">footer</span>&gt;</span>
</code></pre>
<h3 id="heading-appjs">app.js</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">"express"</span>);
<span class="hljs-keyword">const</span> hbs = <span class="hljs-built_in">require</span>(<span class="hljs-string">"hbs"</span>);
<span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">"path"</span>);
<span class="hljs-keyword">const</span> app = express();
app.set(<span class="hljs-string">"view engine"</span>, <span class="hljs-string">"hbs"</span>);
app.set(<span class="hljs-string">"views"</span>, path.join(__dirname, <span class="hljs-string">"/templates/views"</span>));
hbs.registerPartials(path.join(__dirname, <span class="hljs-string">"/templates/partials"</span>));
app.get(<span class="hljs-string">"/"</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {  
    res.render(<span class="hljs-string">"index"</span>, {    
        <span class="hljs-attr">title</span>: <span class="hljs-string">"Home"</span>,    
        <span class="hljs-attr">name</span>: <span class="hljs-string">"Arash Arora"</span>,  
    });
});
app.get(<span class="hljs-string">"/about"</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {  
    res.render(<span class="hljs-string">"about"</span>, {    
        <span class="hljs-attr">title</span>: <span class="hljs-string">"About"</span>,    
        <span class="hljs-attr">name</span>: <span class="hljs-string">"Arash Arora"</span>,  
    });
});
app.listen(<span class="hljs-number">3000</span>, <span class="hljs-function">() =&gt;</span> {  
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Listening on port 3000"</span>);
});
</code></pre>
<p>Everything is the same as I explained in the section on rendering dynamic files in Express – except here we have to <strong>register the partials</strong> to use partials.</p>
<h3 id="heading-how-to-register-partials">How to register partials</h3>
<pre><code class="lang-js">hbs.registerPartials(path_to_partials)
</code></pre>
<p>As we’ve created the partials directory in the templates folder, here is the path of partials:</p>
<pre><code class="lang-js">hbs.registerPartials(path.join(__dirname, <span class="hljs-string">"/templates/partials"</span>));
</code></pre>
<h1 id="heading-wrapping-up">Wrapping Up</h1>
<p>In this article, we've covered Node.js from theory to practice. Although Node.js is a vast topic that you can't learn entirely from a single shorter article, I've done my best to cover some of the essential features to help you get started with the journey.</p>
<p>In a nutshell, we've discussed what Node.js is, which is a non-blocking, event-driven JavaScript runtime that is asynchronous and uses a single thread to perform operations. We've also discussed the most used minimal and flexible Node.js web application framework, Express.</p>
<p>Then we talked about Node.js's NPM, NPX, and Static and Dynamic data rendering.</p>
<p>All in all, Node.js is a fantastic technology to know, and the possibilities are endless because of its vast community.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
