<?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"><channel><title><![CDATA[Pratham Agrawal's Blog]]></title><description><![CDATA[Pratham Agrawal's Blog]]></description><link>https://blogs.agrawalpratham.in</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 15:57:04 GMT</lastBuildDate><atom:link href="https://blogs.agrawalpratham.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Publish Your First NPM Package: A Beginner's Tutorial]]></title><description><![CDATA[Prerequisites

Node.js (version 14 or higher) installed on your system

NPM (version 6 or higher) installed on your system

A GitHub account (optional but recommended)

A code editor or IDE of your choice


Creating a New NPM Package

Open your termi...]]></description><link>https://blogs.agrawalpratham.in/publish-your-first-npm-package</link><guid isPermaLink="true">https://blogs.agrawalpratham.in/publish-your-first-npm-package</guid><category><![CDATA[npm]]></category><category><![CDATA[npm publish]]></category><category><![CDATA[npm packages]]></category><category><![CDATA[beginner]]></category><category><![CDATA[guide]]></category><dc:creator><![CDATA[Pratham Agrawal]]></dc:creator><pubDate>Tue, 01 Oct 2024 12:38:02 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/oZMUrWFHOB4/upload/3454b6e956cc03b97320e608dcebfd96.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-prerequisites"><strong>Prerequisites</strong></h2>
<ul>
<li><p>Node.js (version 14 or higher) installed on your system</p>
</li>
<li><p>NPM (version 6 or higher) installed on your system</p>
</li>
<li><p>A GitHub account (optional but recommended)</p>
</li>
<li><p>A code editor or IDE of your choice</p>
</li>
</ul>
<h2 id="heading-creating-a-new-npm-package"><strong>Creating a New NPM Package</strong></h2>
<ol>
<li><p>Open your terminal or command prompt and navigate to the directory where you want to create your package.</p>
</li>
<li><p>Run the following command to create a new directory for your package:</p>
<pre><code class="lang-bash"> mkdir my-package
</code></pre>
</li>
<li><p>Navigate into the newly created directory:</p>
<pre><code class="lang-bash"> <span class="hljs-built_in">cd</span> my-package
</code></pre>
</li>
</ol>
<h2 id="heading-initializing-the-package"><strong>Initializing the Package</strong></h2>
<ol>
<li><p>Run the following command to initialize a new NPM package:</p>
<pre><code class="lang-bash"> npm init
</code></pre>
</li>
<li><p>Follow the prompts to fill in the required information:</p>
<ul>
<li><p><code>package name</code>: The name of your package (e.g., <code>my-package</code>).</p>
</li>
<li><p><code>version</code>: The initial version of your package (e.g., <code>1.0.0</code>).</p>
</li>
<li><p><code>description</code>: A brief description of your package.</p>
</li>
<li><p><code>entry point</code>: The main file of your package (e.g., <code>index.js</code>).</p>
</li>
<li><p><code>test command</code>: The command to run your tests (e.g., <code>npm test</code>).</p>
</li>
<li><p><code>git repository</code>: The URL of your GitHub repository (optional).</p>
</li>
<li><p><code>keywords</code>: Keywords related to your package (e.g., <code>javascript</code>, <code>utility</code>).</p>
</li>
<li><p><code>author</code>: Your name and email address.</p>
</li>
<li><p><code>license</code>: The license under which your package is released (e.g., <code>MIT</code>).</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-writing-the-package-code"><strong>Writing the Package Code</strong></h2>
<ol>
<li><p>Create a new file called <code>index.js</code> in the root of your package directory:</p>
<pre><code class="lang-bash"> touch index.js
</code></pre>
</li>
<li><p>Open the <code>index.js</code> file in your code editor and add the following code:</p>
<pre><code class="lang-javascript"> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params">name</span>) </span>{ <span class="hljs-built_in">console</span>.log(Hello, ${name}!); }

 <span class="hljs-built_in">module</span>.exports = greet;
</code></pre>
</li>
<li><p>Save the file.</p>
</li>
</ol>
<h2 id="heading-testing-the-package"><strong>Testing the Package</strong></h2>
<ol>
<li><p>Create a new file called <code>test.js</code> in the root of your package directory:</p>
<pre><code class="lang-bash">
 touch test.js
</code></pre>
</li>
<li><p>Open the <code>test.js</code> file in your code editor and add the following code:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">const</span> greet = <span class="hljs-built_in">require</span>(<span class="hljs-string">'./index'</span>);

 describe(<span class="hljs-string">'greet'</span>, <span class="hljs-function">() =&gt;</span> { it(<span class="hljs-string">'should print a greeting message'</span>, <span class="hljs-function">() =&gt;</span> { <span class="hljs-keyword">const</span> message = <span class="hljs-string">'Hello, John!'</span>; <span class="hljs-built_in">console</span>.log = jest.fn(); greet(<span class="hljs-string">'John'</span>); expect(<span class="hljs-built_in">console</span>.log).toHaveBeenCalledWith(message); }); });
</code></pre>
</li>
<li><p>Save the file.</p>
</li>
</ol>
<h2 id="heading-building-the-package"><strong>Building the Package</strong></h2>
<ol>
<li><p>Open your <code>package.json</code> file and add the following script:</p>
<pre><code class="lang-json"> <span class="hljs-string">"scripts"</span>: {
   <span class="hljs-attr">"build"</span>: <span class="hljs-string">"echo 'Building package...'"</span>
 }
</code></pre>
</li>
<li><p>Run the following command to build your package:</p>
<pre><code class="lang-bash"> npm run build
</code></pre>
</li>
</ol>
<h2 id="heading-publishing-the-package"><strong>Publishing the Package</strong></h2>
<ol>
<li><p>Create an NPM account if you haven't already.</p>
</li>
<li><p>Run the following command to login to your NPM account:</p>
<pre><code class="lang-bash"> npm login
</code></pre>
</li>
<li><p>Follow the prompts to enter your NPM username, password, and email address.</p>
</li>
<li><p>Run the following command to publish your package:</p>
<pre><code class="lang-bash"> npm publish
</code></pre>
</li>
<li><p>Follow the prompts to confirm that you want to publish your package.</p>
</li>
</ol>
<h2 id="heading-updating-the-package"><strong>Updating the Package</strong></h2>
<ol>
<li><p>Make changes to your package code.</p>
</li>
<li><p>Update the version number in your <code>package.json</code> file.</p>
</li>
<li><p>Run the following command to publish the updated package:</p>
<pre><code class="lang-bash"> npm publish
</code></pre>
</li>
</ol>
<h2 id="heading-example-use-case"><strong>Example Use Case</strong></h2>
<p>To use your newly published package in another project, run the following command:</p>
<pre><code class="lang-bash">npm install my-package
</code></pre>
<p>Then, in your JavaScript file, import and use the package:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> greet = <span class="hljs-built_in">require</span>(<span class="hljs-string">'my-package'</span>);

greet(<span class="hljs-string">'John'</span>); <span class="hljs-comment">// Output: Hello, John!</span>
</code></pre>
<p>That's it! You've successfully created and published an NPM package.</p>
]]></content:encoded></item><item><title><![CDATA[SEO With NextJs]]></title><description><![CDATA[In the dynamic world of web development, ensuring your website stands out to search engines is as crucial as the development itself. Next.js, a React framework, offers powerful features for building highly performive and SEO-friendly websites. Here, ...]]></description><link>https://blogs.agrawalpratham.in/seo-with-nextjs</link><guid isPermaLink="true">https://blogs.agrawalpratham.in/seo-with-nextjs</guid><category><![CDATA[Next.js]]></category><category><![CDATA[SEO]]></category><category><![CDATA[next.js seo]]></category><category><![CDATA[Server side rendering]]></category><dc:creator><![CDATA[Pratham Agrawal]]></dc:creator><pubDate>Sun, 28 Jul 2024 13:26:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1722172411182/0e7a5340-2c64-4cbe-b1d2-37c97ef03bb8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the dynamic world of web development, ensuring your website stands out to search engines is as crucial as the development itself. Next.js, a React framework, offers powerful features for building highly performive and SEO-friendly websites. Here, we'll dive into strategies and coding examples to optimize your Next.js projects for better search engine rankings.</p>
<h3 id="heading-1-leverage-server-side-rendering-ssr">1. Leverage Server-Side Rendering (SSR)</h3>
<p>Server-side rendering is a cornerstone of SEO-friendly applications. It ensures that your content is fully rendered before reaching the client, making it readily available for search engine crawlers. Next.js makes SSR implementation straightforward, enhancing your content's visibility.</p>
<h3 id="heading-coding-example">Coding Example:</h3>
<p>Implement SSR in your Next.js page by exporting an async function called getServerSideProps. This function runs on the server for each request and can fetch data that will be passed to the page component as props.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getServerSideProps</span>(<span class="hljs-params">context</span>) </span>{
  <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">`https://api.example.com/data`</span>);
  <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> res.json();
  <span class="hljs-keyword">return</span> { <span class="hljs-attr">props</span>: { data } };
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Page</span>(<span class="hljs-params">{ data }</span>) </span>{
  <span class="hljs-comment">// Render data...</span>
}
</code></pre>
<h3 id="heading-2-utilize-static-site-generation-ssg">2. Utilize Static Site Generation (SSG)</h3>
<p>Static Site Generation is another SEO-friendly feature of Next.js. By pre-rendering pages at build time, it makes them instantly available to search engines and users alike, reducing load times and improving indexation.</p>
<h3 id="heading-coding-example-1">Coding Example:</h3>
<p>To use SSG, export an async function called getStaticProps in your Next.js page. This function generates HTML at build time, which can be cached and served instantly.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getStaticProps</span>(<span class="hljs-params">context</span>) </span>{
  <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">`https://api.example.com/data`</span>);
  <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> res.json();
  <span class="hljs-keyword">return</span> { <span class="hljs-attr">props</span>: { data } };
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">HomePage</span>(<span class="hljs-params">{ data }</span>) </span>{
  <span class="hljs-comment">// Render data...</span>
}
</code></pre>
<h3 id="heading-3-optimize-meta-tags-and-titles">3. Optimize Meta Tags and Titles</h3>
<p>Meta tags and titles play a vital role in SEO, influencing how your pages are displayed in search results. Next.js's Head component allows you to dynamically set these tags per page, improving relevancy and click-through rates.</p>
<h3 id="heading-coding-example-2">Coding Example:</h3>
<p>Use the Head component from next/head to include SEO-relevant information like title and description meta tags.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> Head <span class="hljs-keyword">from</span> <span class="hljs-string">'next/head'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">HomePage</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&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>Your Page Title<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"description"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"A brief description of your page"</span> /&gt;</span>
         {/*Additional meta tags*/}
        <span class="hljs-tag">&lt;/<span class="hljs-name">Head</span>&gt;</span>
      {/* Page content */}
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
}
</code></pre>
<h3 id="heading-4-implement-dynamic-routing-for-seo">4. Implement Dynamic Routing for SEO</h3>
<p>Dynamic routing can enhance your SEO by enabling the creation of SEO-friendly URLs. Next.js's file-based routing system and dynamic routes feature make it easy to set up.</p>
<h3 id="heading-coding-example-3">Coding Example:</h3>
<p>Create dynamic routes in Next.js by adding square brackets to a page's file name, like [id].js. Use getStaticPaths to specify which paths to pre-render.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getStaticPaths</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> {
    <span class="hljs-attr">paths</span>: [
      { <span class="hljs-attr">params</span>: { <span class="hljs-attr">id</span>: <span class="hljs-string">'1'</span> } },
      { <span class="hljs-attr">params</span>: { <span class="hljs-attr">id</span>: <span class="hljs-string">'2'</span> } },
    ],
    <span class="hljs-attr">fallback</span>: <span class="hljs-literal">false</span>,
  };
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getStaticProps</span>(<span class="hljs-params">{ params }</span>) </span>{
  <span class="hljs-comment">// Fetch data based on `params.id`</span>
}
</code></pre>
<h3 id="heading-5-enhance-website-performance">5. Enhance Website Performance</h3>
<p>Website speed is a crucial SEO factor. Next.js offers automatic code splitting, optimized images, and more to boost performance. Use the next/image component for optimized image loading.</p>
<h3 id="heading-coding-example-4">Coding Example:</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> Image <span class="hljs-keyword">from</span> <span class="hljs-string">'next/image'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MyImageComponent</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Image</span>
      <span class="hljs-attr">src</span>=<span class="hljs-string">"/path/to/image.jpg"</span>
      <span class="hljs-attr">alt</span>=<span class="hljs-string">"Description"</span>
      <span class="hljs-attr">width</span>=<span class="hljs-string">{500}</span>
      <span class="hljs-attr">height</span>=<span class="hljs-string">{300}</span>
    /&gt;</span></span>
  );
}
</code></pre>
<h3 id="heading-6-generating-site-maps">6. Generating Site Maps</h3>
<p>A sitemap helps search engines discover and index your web pages more efficiently. Next.js provides a way to generate a sitemap using the <code>sitemap</code> package. Check out the Next.js documentation on <a target="_blank" href="https://nextjs.org/docs/app/api-reference/functions/generate-sitemaps">sitemap generation</a> for detailed instructions, or you can use some packages <a target="_blank" href="https://www.npmjs.com/package/next-sitemap">next-sitemap</a> to generate site map automatically.</p>
<h3 id="heading-7-monitoring-analytics">7. Monitoring Analytics</h3>
<p>Integrate Google Analytics into your Next.js application to track and analyze traffic, user behavior, and conversion rates.Also Google Search Console provides valuable insights into your website’s organic performance, including search queries, click-through rates, and crawl errors. Verify your Next.js website with Google Search Console and leverage its data for SEO improvements.</p>
<h3 id="heading-ia"> </h3>
<p>Conclusion</p>
<p>Optimizing your Next.js website for search engines is a multifaceted approach that involves server-side rendering, static site generation, meta tags optimization, dynamic routing, and performance enhancements. By implementing these strategies and using the coding examples provided, you can significantly improve your website's SEO performance, ensuring better visibility and higher rankings in search engine results.</p>
<p>Regularly updating your content, monitoring your site's performance, and adapting to new SEO trends and algorithm updates will help maintain and improve your rankings over time.</p>
]]></content:encoded></item><item><title><![CDATA[Streamlining Web Development with Powerful Tools from Google I/O Connect]]></title><description><![CDATA[The recent Google I/O Connect event in Bangalore was a treasure trove of exciting announcements for web developers. With a focus on streamlining workflows and empowering developers to build more feature-rich applications, the event showcased a range ...]]></description><link>https://blogs.agrawalpratham.in/streamlining-web-development-with-powerful-tools-from-google-io-connect</link><guid isPermaLink="true">https://blogs.agrawalpratham.in/streamlining-web-development-with-powerful-tools-from-google-io-connect</guid><category><![CDATA[io connect]]></category><category><![CDATA[Google]]></category><category><![CDATA[Firebase]]></category><category><![CDATA[Firebase App Hosting]]></category><dc:creator><![CDATA[Pratham Agrawal]]></dc:creator><pubDate>Wed, 17 Jul 2024 18:13:25 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1721239878912/f3e5ea41-4cd0-4762-b6fc-85f47d55f585.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The recent Google I/O Connect event in Bangalore was a treasure trove of exciting announcements for web developers. With a focus on streamlining workflows and empowering developers to build more feature-rich applications, the event showcased a range of innovative tools and technologies.</p>
<p>One of the most significant announcements was the ability to deploy Next.js and Angular web apps directly from GitHub to Cloud Run and Cloud CDN. This eliminates the need for manual configuration and deployment processes, saving developers valuable time and effort. By leveraging the power of Cloud Run's serverless architecture and Cloud CDN's global network for content delivery, developers can ensure their web applications are scalable, performant, and reach users worldwide with minimal hassle.</p>
<p>Another key highlight was the introduction of new Firebase APIs. These APIs promise to further simplify the process of building feature-rich web applications. With a focus on reducing code requirements, developers can integrate functionalities like authentication, databases, and cloud storage seamlessly into their applications. This allows them to concentrate on core development tasks and deliver exceptional user experiences faster.</p>
<p>The Cloud Console also received an upgrade, offering even more helpful metrics for monitoring application performance. With a clearer understanding of how their applications are functioning, developers can make data-driven decisions for optimization and ensure their applications are running smoothly.</p>
<p>Perhaps the most intriguing prospect comes from the integration of Gemini's AI capabilities. While details remain scarce, the potential for incorporating AI to enhance web applications is significant. This could involve intelligent user interfaces, data-driven personalization, or even AI-powered content generation.</p>
<p>The confluence of these advancements paints a bright picture for the future of web development. By leveraging these powerful tools and technologies, developers can create next-generation web applications that are faster, more scalable, and deliver exceptional user experiences.</p>
<p><strong>Stay tuned for further updates on these exciting developments, and if you're a web developer, be sure to explore these tools and APIs to see how they can revolutionize your workflow!</strong></p>
]]></content:encoded></item></channel></rss>