<?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: Shoieb Alam</title>
    <description>The latest articles on DEV Community by Shoieb Alam (@shoiebalam).</description>
    <link>https://dev.to/shoiebalam</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%2F778680%2F6dabe908-f345-4981-8420-71af0d1a3324.jpeg</url>
      <title>DEV Community: Shoieb Alam</title>
      <link>https://dev.to/shoiebalam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shoiebalam"/>
    <language>en</language>
    <item>
      <title>Beginner's Guide to Node.js with Express</title>
      <dc:creator>Shoieb Alam</dc:creator>
      <pubDate>Thu, 23 Dec 2021 09:48:43 +0000</pubDate>
      <link>https://dev.to/shoiebalam/beginners-guide-to-nodejs-with-express-53oh</link>
      <guid>https://dev.to/shoiebalam/beginners-guide-to-nodejs-with-express-53oh</guid>
      <description>&lt;p&gt;We'll look at the Express framework in this discussion. This framework is designed to operate as a basic and versatile Node.js web application framework, with a powerful set of capabilities for creating single and multipage web applications, as well as hybrid web applications.&lt;/p&gt;

&lt;p&gt;Here you'll find out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is Express.js and how does it work?&lt;/li&gt;
&lt;li&gt;Express installation and use&lt;/li&gt;
&lt;li&gt;Introduction of routes?&lt;/li&gt;
&lt;li&gt;Express.js Web server example&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What is Express.js and how does it work?&lt;/strong&gt;&lt;br&gt;
Express.js is a Node.js web application server framework for constructing single-page, multi-page, and hybrid web applications.&lt;/p&gt;

&lt;p&gt;For node.js, it has become the standard server framework. The MERN stack is made up of several components, one of which is Express.&lt;/p&gt;

&lt;p&gt;The MERN is a free and open-source JavaScript software stack that includes the following components for creating dynamic web pages and online applications.&lt;/p&gt;

&lt;p&gt;The Express.js framework makes it simple to create an application that can handle a variety of requests, including GET, PUT, POST, and DELETE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Express installation and use&lt;/strong&gt;&lt;br&gt;
The Node Package Manager is used to install Express. This may be done by running the command line with the following line.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install express&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The command above instructs the Node package management to fetch and install the appropriate express modules.&lt;/p&gt;

&lt;p&gt;Let's make a simple "Hello World" application with our newly installed Express framework.&lt;/p&gt;

&lt;p&gt;Our application will develop a simple server module that will listen on port 3000. Whenever a browser query is performed on this port number, the server application will respond with a 'Hello' World' message to the client.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mCDpTI_6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d4tphhq1obziiiwiwpo4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mCDpTI_6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d4tphhq1obziiiwiwpo4.png" alt="Image description" width="880" height="492"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let understand the above code:&lt;br&gt;
The need function is being used to include the "express module" in our first line of code.&lt;br&gt;
We must first create an object of the express module before utilizing it.&lt;/p&gt;

&lt;p&gt;We're going to make a callback function in this example. When someone visits &lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt;, our web application's root, this method will be called. The string 'Hello World' will be sent to the web page via the callback method.&lt;/p&gt;

&lt;p&gt;We send the string "Hello World" back to the client in the callback function. To transmit content back to the web page, use the 'res' argument. The 'request' module provides the 'res' argument, which allows you to transmit material back to the web page.&lt;/p&gt;

&lt;p&gt;The listen to function is then used to make our server program listen for client requests on port 3000. You can use this field to specify any available port. &lt;/p&gt;

&lt;p&gt;When you run your code in the browser, the following Output will appear if the command was successfully executed.&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xy_OSWtp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xknvum1th75nhm1hz2ex.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xy_OSWtp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xknvum1th75nhm1hz2ex.jpg" alt="Image description" width="600" height="353"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Based on the results,&lt;/p&gt;

&lt;p&gt;If you go to the URL of localhost on port 3000, you'll notice that the string 'Hello World' is shown on the website.&lt;/p&gt;

&lt;p&gt;Because we specified in our code that the server should listen on port 3000, we are able to see the output when visiting this URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introduction of routes?&lt;/strong&gt;&lt;br&gt;
The manner an application replies to a client request to a certain endpoint is determined by routing.&lt;/p&gt;

&lt;p&gt;For example, for various URLs, a client can make a GET, POST, PUT, or DELETE http request.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://localhost:3000/products&lt;br&gt;
http://localhost:3000/users&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the preceding example,&lt;/p&gt;

&lt;p&gt;If you make a GET request for the first URL, you should get a list of books as a response.&lt;br&gt;
If the second URL is requested using GET, the result should ideally be a list of Students.&lt;br&gt;
So, depending on the URL that is accessed, the webserver will run a different function, and the response will be provided to the client appropriately. The concept of routing is as follows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Express.js Web server example&lt;/strong&gt;&lt;br&gt;
We know that how routing can help us determine which outputs to show. The majority of current online apps employ this type of routing. The other aspect of a web server is the use of Node js templates.&lt;/p&gt;

&lt;p&gt;For setting up the server navigate to the root directory from the terminal and run the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$npm init -y&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The package.json file will be generated automatically by the program. Then, to install Express, use the command below, which will save it as a dependency inside the package.json.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$npm install express --save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TrjbneWp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrbkkkkdeq7t7x3zfewj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TrjbneWp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vrbkkkkdeq7t7x3zfewj.png" alt="Image description" width="880" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let understand the above code:&lt;/p&gt;

&lt;p&gt;Lines 1 and 2 are required for us to use Express inside our server.js file.&lt;/p&gt;

&lt;p&gt;Line 3 – This instructs the Express server to run on a specific port.&lt;/p&gt;

&lt;p&gt;Line 6 – displays a message on the console stating that the server is operating normally.&lt;/p&gt;

&lt;p&gt;Lines 9 to 11 – This will create a GET route that will be retrieved later from our client-side React App.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The express framework is the most widely used framework for Node.js application development. The express framework is a server-side framework built on top of the node.js framework that aids in the rapid building of server-side applications.&lt;/p&gt;

&lt;p&gt;Routes are used to direct users to different portions of the web application depending on their request. Depending on what has to be shown to the user, the response for each route can be different&lt;/p&gt;

&lt;p&gt;The Express backend can do a lot of things, like make database requests, but in this post, we'll focus on how to quickly connect to the backend Express server from a client-side React App.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>express</category>
      <category>node</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Lifecycle Story of React Components</title>
      <dc:creator>Shoieb Alam</dc:creator>
      <pubDate>Wed, 22 Dec 2021 10:01:24 +0000</pubDate>
      <link>https://dev.to/shoiebalam/lifecycle-story-of-react-components-3ne0</link>
      <guid>https://dev.to/shoiebalam/lifecycle-story-of-react-components-3ne0</guid>
      <description>&lt;p&gt;Components are used in React applications to break and isolate distinct aspects of the online user experience into separate pieces. These components work independently and return React elements in JSX using a render method. These elements specify how the user should be presented with that part.&lt;/p&gt;

&lt;p&gt;Some of the earlier lifecycle methods have been judged to be inappropriate to use in recent React versions and will be deprecated in React 17. We shall not learn about the soon-to-be deprecated unsafe lifecycle methods here.&lt;/p&gt;

&lt;p&gt;The React component lifetime is made up of these three milestones. Mounting, updating, and unmounting are the three steps that each component goes through. You can think of it as our natural life cycle, in which we are born, grow, and eventually die. React components are generated by mounting them on the DOM, then changing or growing them through updates, and lastly removing or unmounting them from the DOM.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fl6r5ij9pvu44877l9n5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fl6r5ij9pvu44877l9n5l.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The whole modern lifespan of React components is shown here, along with the necessary lifecycle functions. Specific lifecycle methods are provided by React and can be used to conduct specific tasks in different phases. React component lifecycle methods are what they're named.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 1: Mounting
&lt;/h2&gt;

&lt;p&gt;The creation of the component is the subject of this phase. The component is added to the DOM at this point.&lt;br&gt;
For this phase, the following lifecycle techniques are available:&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;constructor(): *&lt;/em&gt;&lt;br&gt;
We may need to use a constructor() method to initialize our component before we begin the mounting step. When we need to initialize state and bind methods to our component, we use this. This is the only location where this.state is assigned explicitly.&lt;/p&gt;

&lt;p&gt;static getDerivedStateFromProps()&lt;br&gt;
This is one of the more recent lifecycle methods to be introduced by the React team.&lt;br&gt;
This will be a safer replacement to the previous componentWillReceiveProps() lifecycle function.&lt;br&gt;
It is invoked right before the render() method is called.&lt;/p&gt;

&lt;p&gt;This is a static function that does not have access to the "this" variable. getDerivedStateFromProps() generates a state-updating object in response to prop changes. It may return null if there is no change in status.&lt;/p&gt;

&lt;p&gt;This approach is likewise only available in rare circumstances where the state of a component is affected by changes in its props.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;render():&lt;/strong&gt;&lt;br&gt;
The render() method seems to be the most commonly used method in the lifecycle. It can be found in all React classes. This is due to the fact that with React, the only needed function within a class component is render().&lt;/p&gt;

&lt;p&gt;It manages the rendering of your component to the user interface, as the name implies. It happens while you're installing and upgrading your component.&lt;/p&gt;

&lt;p&gt;An example of a simple render() in React is shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fwxednvh78mssthopc15m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fwxednvh78mssthopc15m.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The render() function, as you can see in the sample above, returns JSX that is shown in the UI. If there is nothing to render for that component, render() might also return null.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;componentDidMount():&lt;/strong&gt;&lt;br&gt;
componentDidMount() is the last function in this phase. After the render function has completed, this method will be called immediately. This is where we interface directly with the browser if we need to. We can perform an API request and use the answer to update the state of the components. We can populate the content with information obtained from another endpoint. SetState() should be used in this case since it will re-call the render method and manage asynchronous activities like fetch requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 2: Updating
&lt;/h2&gt;

&lt;p&gt;This second phase illustrates when a component's props or state change and it has to update. These modifications can be made within the component or via the backend. The render function will be triggered again as a result of these modifications.&lt;/p&gt;

&lt;p&gt;The first method called in this phase is getDeprivedStateFromProps(). This is the same procedure that was employed during the mounting process. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;shouldComponentUpdate():&lt;/strong&gt;&lt;br&gt;
When you don't want React to render your state or prop updates, this lifecycle might be useful.&lt;/p&gt;

&lt;p&gt;By default, the component re-renders whenever setState() is used. The shouldComponentUpdate() function informs React whether or not a component is impacted by state and prop changes.&lt;/p&gt;

&lt;p&gt;Keep in mind that this lifecycle function should only be utilized when specific speed enhancements are required. In the shouldComponentUpdate() lifecycle, you can't change the state of a component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;getSnapshotBeforeUpdate()&lt;/strong&gt;&lt;br&gt;
Another interesting lifecycle function released in React lately is getSnapshotBeforeUpdate(). &lt;/p&gt;

&lt;p&gt;It's called just when the DOM is about to be changed. componentDidUpdate() receives the value returned from getSnapshotBeforeUpdate().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;componentDidUpdate():&lt;/strong&gt;&lt;br&gt;
This is the last method called in this phase. It accepts the same props and state variables as the previous method, but it also accepts the return value getSnapshotBeforeUpdate() as a third argument (if present).&lt;/p&gt;

&lt;p&gt;It's usually utilized to perform extra fetch queries if the current and previous props and state values are compared. As a result, setState may be used within a conditional expression.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 3: Unmounting
&lt;/h2&gt;

&lt;p&gt;The component is finally unmounted from the DOM in the unmounting process. The lifespan of a component comes to an end at this point. We only have one lifecycle method accessible to us at this time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;componentWillUnmount():&lt;/strong&gt;&lt;br&gt;
This lifecycle method is invoked shortly before the component is unmounted and deleted, as the name implies. If you need to undertake any cleanup work, this is the place to do it.&lt;/p&gt;

&lt;p&gt;We can't execute setState() during this lifecycle function since this component will never be re-rendered.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
