<?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: thakur-sahab999</title>
    <description>The latest articles on DEV Community by thakur-sahab999 (@thakursahab999).</description>
    <link>https://dev.to/thakursahab999</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%2F1041236%2Fdbd00440-c00c-43ee-a639-c1b585c17dda.jpeg</url>
      <title>DEV Community: thakur-sahab999</title>
      <link>https://dev.to/thakursahab999</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thakursahab999"/>
    <language>en</language>
    <item>
      <title>Next Js Tutorial</title>
      <dc:creator>thakur-sahab999</dc:creator>
      <pubDate>Tue, 14 Mar 2023 07:35:46 +0000</pubDate>
      <link>https://dev.to/thakursahab999/next-js-tutorial-4m4k</link>
      <guid>https://dev.to/thakursahab999/next-js-tutorial-4m4k</guid>
      <description>&lt;h2&gt;
  
  
  What is Next JS  ?
&lt;/h2&gt;

&lt;p&gt;Before moving on learning about Next Js we should know what it is&lt;br&gt;
Next.js is a popular open-source framework for building React applications that allows developers to create server-rendered React applications with ease. &lt;/p&gt;
&lt;h2&gt;
  
  
  Why Did we used NextJs ?
&lt;/h2&gt;

&lt;p&gt;It provides a set of tools and features that make building and deploying modern web applications more efficient, such as:&lt;/p&gt;

&lt;p&gt;Server-side rendering: Next.js supports server-side rendering (SSR) out of the box, which means that the initial HTML is generated on the server and sent to the client, resulting in faster page loads and better SEO.&lt;/p&gt;

&lt;p&gt;Automatic code splitting: Next.js automatically splits the code into smaller chunks, so only the code needed for each page is loaded, reducing the initial load time of the application.&lt;/p&gt;

&lt;p&gt;Static site generation: Next.js allows for static site generation (SSG), which pre-renders pages at build time, resulting in even faster load times and reduced server load.&lt;/p&gt;

&lt;p&gt;API routes: Next.js provides an easy way to create API routes, allowing for easy integration with external data sources.&lt;/p&gt;

&lt;p&gt;Built-in CSS support: Next.js has built-in support for styling using CSS modules or styled-components, making it easier to write and maintain CSS for your application.&lt;/p&gt;

&lt;p&gt;Overall, Next.js makes it easier and faster to build and deploy modern web applications, while providing features that improve performance, SEO, and development experience.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequsites of learning Next Js:
&lt;/h2&gt;

&lt;p&gt;Before diving into learning Next.js, it's recommended that you have a solid foundation in the following technologies:&lt;/p&gt;

&lt;p&gt;HTML and CSS: Next.js is built on top of React, which requires a solid understanding of HTML and CSS to build responsive, well-designed web applications.&lt;/p&gt;

&lt;p&gt;JavaScript: Next.js is a JavaScript framework, so you should have a good understanding of the language and its fundamentals, including variables, functions, arrays, objects, loops, and conditional statements.&lt;/p&gt;

&lt;p&gt;React: Next.js is built on top of React, so you should have a good understanding of React's core concepts, including components, state, props, and the virtual DOM.&lt;/p&gt;

&lt;p&gt;Node.js: Next.js uses Node.js to run server-side rendering and other server-side tasks. You should have a good understanding of Node.js and how to use it to create web applications.&lt;/p&gt;

&lt;p&gt;Git: Git is a version control system that is commonly used for managing code repositories. You should be familiar with Git and how to use it to manage your code.&lt;/p&gt;

&lt;p&gt;Additionally, it's recommended that you have some experience building web applications before diving into Next.js. While Next.js provides many benefits over vanilla React, it can still be complex, so having experience building web applications can help you better understand the concepts and tools used in Next.js.&lt;/p&gt;
&lt;h2&gt;
  
  
  System Prerequsites
&lt;/h2&gt;

&lt;p&gt;To get started with Next.js, you'll need to ensure that your system meets the following prerequisites:&lt;/p&gt;

&lt;p&gt;Node.js: Next.js is built on top of Node.js, so you'll need to have Node.js installed on your system. You can download the latest version of Node.js from the official website: Node.js &lt;/p&gt;

&lt;p&gt;NPM: NPM (Node Package Manager) is used to manage the dependencies for your Next.js project. It comes bundled with Node.js, so you should have it installed by default.&lt;/p&gt;

&lt;p&gt;Git: Git is a version control system that is commonly used for managing code repositories. You should have Git installed on your system to manage your Next.js project.&lt;/p&gt;
&lt;h2&gt;
  
  
  Lets Create a NextJs App
&lt;/h2&gt;

&lt;p&gt;Here's a step-by-step guide to building a Next.js app that shows images in cards, implements infinite scrolling, and uses Server Side Rendering to fetch data using getServerSideProps&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Set Up the Project&lt;/strong&gt;&lt;br&gt;
To get started, create a new Next.js project by running the following commands:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-next-app&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;my-app cd my-app&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Step 2: Install Dependencies&lt;/strong&gt;&lt;br&gt;
Next, install the following dependencies:&lt;/p&gt;

&lt;p&gt;npm install axios react-infinite-scroll-component tailwindcss&lt;/p&gt;

&lt;p&gt;We'll use the axios library to make HTTP requests to the API, react-infinite-scroll-component to implement infinite scrolling, and tailwindcss to style our components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Create Image Card Component&lt;/strong&gt;&lt;br&gt;
Create a new file called ImageCard.js in the components directory and add the following code:&lt;/p&gt;

&lt;p&gt;code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

function ImageCard({ image }) {
  return (
    &amp;lt;div className="rounded overflow-hidden shadow-lg"&amp;gt;
      &amp;lt;img src={image.urls.regular} alt={image.alt_description} /&amp;gt;
      &amp;lt;div className="px-6 py-4"&amp;gt;
        &amp;lt;div className="font-bold text-xl mb-2"&amp;gt;{image.user.username}&amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default ImageCard;

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

&lt;/div&gt;



&lt;p&gt;This component takes an image object as a prop and displays it in a card with the photographer's name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Create Infinite Scroll Component&lt;/strong&gt;&lt;br&gt;
Create a new file called InfiniteScrollImages.js in the components directory and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from 'react';
import axios from 'axios';
import InfiniteScroll from 'react-infinite-scroll-component';
import ImageCard from './ImageCard';

function InfiniteScrollImages() {
  const [images, setImages] = useState([]);
  const [page, setPage] = useState(1);

  useEffect(() =&amp;gt; {
    fetchImages();
  }, []);

  const fetchImages = async () =&amp;gt; {
    const response = await axios.get(`https://api.unsplash.com/photos`, {
      params: {
        client_id: '&amp;lt;YOUR_API_KEY&amp;gt;',
        page: page,
        per_page: 9,
      },
    });

    setImages((prevImages) =&amp;gt; [...prevImages, ...response.data]);
    setPage((prevPage) =&amp;gt; prevPage + 1);
  };

  return (
    &amp;lt;InfiniteScroll
      dataLength={images.length}
      next={fetchImages}
      hasMore={true}
      loader={&amp;lt;h4&amp;gt;Loading...&amp;lt;/h4&amp;gt;}
    &amp;gt;
      &amp;lt;div className="grid grid-cols-3 gap-4"&amp;gt;
        {images.map((image) =&amp;gt; (
          &amp;lt;ImageCard key={image.id} image={image} /&amp;gt;
        ))}
      &amp;lt;/div&amp;gt;
    &amp;lt;/InfiniteScroll&amp;gt;
  );
}

export default InfiniteScrollImages;

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

&lt;/div&gt;



&lt;p&gt;This component uses the useState hook to store the images and the page number. We use the useEffect hook to fetch the images when the component mounts. The fetchImages function makes an HTTP request to the Unsplash API to get the images and updates the state with the new images and the new page number. Finally, the InfiniteScroll component wraps the image cards and fetches more images when the user scrolls to the bottom of the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Create Index Page&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function getServerSideProps() {
    const { data } = await 
    axios.get(`https://api.unsplash.com/photos/random`, {
      params: {
        client_id: '&amp;lt;YOUR_API_KEY&amp;gt;',
        count: 9,
      },
  });

  return {
    props: {
      initialImages: data,
    },
  };
}

export default function Home({ initialImages }) {
  return (
    &amp;lt;div className="container mx-auto my-8"&amp;gt;
      &amp;lt;h1 className="text-4xl font-bold mb-8"&amp;gt;Infinite Scroll Images&amp;lt;/h1&amp;gt;
      &amp;lt;InfiniteScrollImages initialImages={initialImages} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;This page uses the getServerSideProps function to fetch the initial set of images on the server side. We make a request to the Unsplash API to get 9 random images and pass them to the InfiniteScrollImages component as a prop. Finally, we render the InfiniteScrollImages component on the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Add Tailwind CSS&lt;/strong&gt;&lt;br&gt;
Next.js comes with built-in support for CSS modules, so we can easily add Tailwind CSS to our project. Create a new file called styles/globals.css and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, import this file in the pages/_app.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import '../styles/globals.css';

function MyApp({ Component, pageProps }) {
  return &amp;lt;Component {...pageProps} /&amp;gt;;
}

export default MyApp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 7: Add API Key&lt;/strong&gt;&lt;br&gt;
To use the Unsplash API, you'll need to create an account and generate an access key. Once you have your access key, replace  in the InfiniteScrollImages.js and index.js files with your actual key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8: Start the Development Server&lt;/strong&gt;&lt;br&gt;
Finally, start the development server by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Visit &lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt; in your browser to see the app in action.&lt;/p&gt;

&lt;p&gt;That's it! You've built a Next.js app that shows images in cards, implements infinite scrolling, and uses Server Side Rendering to fetch data using getServerSideProps.&lt;/p&gt;

&lt;p&gt;Push the code to the gitLab/gitHub&lt;/p&gt;
&lt;h2&gt;
  
  
  Now Lets Deploy It
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Launch an EC2 Instance&lt;/strong&gt;&lt;br&gt;
First, launch an EC2 instance using the AWS Management Console. Make sure to select an instance type that meets your needs and configure the security group to allow incoming traffic on port 80 (HTTP) and 443 (HTTPS).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Connect to the Instance&lt;/strong&gt;&lt;br&gt;
Once the instance is launched, connect to it using SSH. You can use the ssh command in your terminal or use a tool like PuTTY if you're on a Windows machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -i &amp;lt;PATH_TO_PRIVATE_KEY&amp;gt; &amp;lt;USER&amp;gt;@&amp;lt;PUBLIC_IP_ADDRESS&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Replace , , and  with the appropriate values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Install Nginx&lt;/strong&gt;&lt;br&gt;
Next, install Nginx on the instance using the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
sudo apt install nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Clone the project&lt;/strong&gt;&lt;br&gt;
Next, install Nginx on the instance using the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /var/www/html
sudo git clone &amp;lt;repo url&amp;gt;
cd my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: Configure Nginx&lt;/strong&gt;&lt;br&gt;
Create a new file at /etc/nginx/sites-available/default and add the following configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
        server_name www.DOMAINNAME.com DOMAINNAME.com;

        index index.html index.htm;
        root /var/www/html/my-app; #Make sure your using the full path

        # Serve any static assets with NGINX
        location /_next/static {
            alias /var/www/html/my-app/.next/static;
            add_header Cache-Control "public, max-age=3600, immutable";
        }

        location / {
            try_files $uri.html $uri/index.html # only serve html files from this dir
            @public
            @nextjs;
            add_header Cache-Control "public, max-age=3600";
        }

        location @public {
            add_header Cache-Control "public, max-age=3600";
        }

        location / {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }

        location @nextjs {
            # reverse proxy for next server
            proxy_pass http://localhost:3000; #Don't forget to update your port number
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }

        listen 80 default_server;
        listen [::]:80;
}


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

&lt;/div&gt;



&lt;p&gt;Replace  with your domain name or public IP address.&lt;/p&gt;

&lt;p&gt;This configuration tells Nginx to listen on port 80 and proxy requests to the Next.js app running on localhost:3000.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Restart Nginx&lt;/strong&gt;&lt;br&gt;
Once you've added the configuration, restart Nginx using the following command:&lt;/p&gt;

&lt;p&gt;sudo systemctl restart nginx&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Install PM2&lt;/strong&gt;&lt;br&gt;
Install PM2 globally on the instance using the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo npm install -g pm2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7: Build and Start the Next.js App&lt;/strong&gt;&lt;br&gt;
In the root directory of your Next.js app, build the production version of the app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /var/www/html/my-app
npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, start the app using PM2:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pm2 start npm --name "&amp;lt;APP_NAME&amp;gt;" -- start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Replace  with a name for your app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8: Save the PM2 Configuration&lt;/strong&gt;&lt;br&gt;
Save the PM2 configuration to ensure that your app will be restarted if the instance is restarted:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pm2 save&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Step 9: Access the App&lt;/strong&gt;&lt;br&gt;
Visit your domain name or public IP address in your browser to access the app. Nginx will proxy requests to the Next.js app running on localhost:3000.&lt;/p&gt;

&lt;p&gt;Congratulations, you've successfully deployed your Next.js app on an AWS EC2 instance using Nginx as a reverse proxy server and PM2 as a process manager!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>news</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Hi Community I need your help</title>
      <dc:creator>thakur-sahab999</dc:creator>
      <pubDate>Mon, 13 Mar 2023 19:58:32 +0000</pubDate>
      <link>https://dev.to/thakursahab999/hi-community-i-need-your-help-5556</link>
      <guid>https://dev.to/thakursahab999/hi-community-i-need-your-help-5556</guid>
      <description>&lt;p&gt;Hi Community&lt;br&gt;
I'm frontend Engineer having experience of 1 year &lt;br&gt;
Tech Stack (React, Redux, NextJs, Tailwind)&lt;br&gt;
I'm struggling to start my freelancing journey&lt;br&gt;
I need your help to guide me about it &lt;/p&gt;

&lt;p&gt;Also I'm open for remote jobs if anyone interested&lt;/p&gt;

&lt;p&gt;Thanks for your support&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>nextjs</category>
      <category>community</category>
    </item>
  </channel>
</rss>
