<?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>Forem: Yessine Agrebi</title>
    <description>The latest articles on Forem by Yessine Agrebi (@yessine-agrebi).</description>
    <link>https://forem.com/yessine-agrebi</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%2F854433%2Ff4709298-0eae-4ced-91e1-c684f0e1cd24.png</url>
      <title>Forem: Yessine Agrebi</title>
      <link>https://forem.com/yessine-agrebi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/yessine-agrebi"/>
    <language>en</language>
    <item>
      <title>Why is React so popular?</title>
      <dc:creator>Yessine Agrebi</dc:creator>
      <pubDate>Mon, 29 Aug 2022 19:24:00 +0000</pubDate>
      <link>https://forem.com/yessine-agrebi/why-is-react-so-popular-2gdg</link>
      <guid>https://forem.com/yessine-agrebi/why-is-react-so-popular-2gdg</guid>
      <description>&lt;p&gt;** Why is React so popular?&lt;br&gt;
**&lt;br&gt;
Before we start talking about popularity, let's understand what React is in the first place.&lt;/p&gt;

&lt;p&gt;React is a javascript library developed by Facebook, it allows developers to easily create user interfaces for web and mobile (React Native).&lt;/p&gt;

&lt;p&gt;Now we will demonstrate how its become so popular by listing some of its features.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Flexibility:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
React flexibility can offer a huge advantage, it allows us to determine how to handle routing, folders structure and even testing.&lt;/p&gt;

&lt;p&gt;One other important aspect of React’s flexibility is its ability to be sprinkled into existing applications. Individual elements in a page can be replaced by React, until the entire application makes the transition. (This is actually how Facebook slowly moved from server-rendered PHP to client-side rendered React.).&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Developer Experience:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
 React offers the option of declaring classes or functions for components, which in turn allows HTML to be housed within JavaScript. This design is opposite to competitors like Angular or Ember, which require developers to learn a special syntax. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Community Support:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
React is in the top most starred repos on GitHub, and it’s downloaded more than 6.6 million times every week. But more important than the number of developers using React is the quality of their experience with the framework.&lt;/p&gt;

&lt;p&gt;For those who need support there are hundreds of thousands of react-related stackoverflow answers available to peruse.&lt;/p&gt;

&lt;p&gt;With an ecosystem that includes popular names like React Router, React Redux, the community is second to none.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Performance:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
While React isn’t necessarily the absolute fastest technologie available, its use of a virtual DOM helps it benchmark quite well compared to the competition. This saves battery and CPU, and simplifies the programming model by re-rendering the screen when necessary.&lt;/p&gt;

&lt;p&gt;In conclusion, React is a good library to work with but it’s not perfect. It has many advantages. We will talk about them in another article.&lt;/p&gt;

&lt;h1&gt;
  
  
  javascript #html #react #github #design #programming #community #facebook #technologie #testing #developer
&lt;/h1&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Most Used Git Commands</title>
      <dc:creator>Yessine Agrebi</dc:creator>
      <pubDate>Sun, 31 Jul 2022 12:48:59 +0000</pubDate>
      <link>https://forem.com/yessine-agrebi/most-used-git-commands-5b4</link>
      <guid>https://forem.com/yessine-agrebi/most-used-git-commands-5b4</guid>
      <description>&lt;h2&gt;
  
  
  What is Git ?
&lt;/h2&gt;

&lt;p&gt;Git is one of the most popular Version Control Systems. It is a crucial part of daily programming.&lt;br&gt;
In this article you will find the most used commands that every developer should know.&lt;/p&gt;

&lt;h2&gt;
  
  
  Git Clone
&lt;/h2&gt;

&lt;p&gt;GIT CLONE :For downloading an existing project&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git clone &amp;lt;https://name-of-repository-link&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Git Branch
&lt;/h2&gt;

&lt;p&gt;Give the ability to work in parallel on the same project.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;git branch&lt;/strong&gt; : New branch&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git push -u  &lt;/strong&gt; : Push the modification into the branch&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git branch -list&lt;/strong&gt; : List all the branches&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git branch -d &lt;/strong&gt; : Delete the branch&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git checkout&lt;/strong&gt; : Switch to new branch (create it if doesn't exist)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git status&lt;/strong&gt; : Give the necessary informations about the current branch.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Git add / commit / push / pull / revert
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;git add &lt;/strong&gt; : Include changes to the next commit&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git commit -m "commit-message"&lt;/strong&gt;: Used to save modification under a commit with generated id.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git push  &lt;/strong&gt; : Used to send the updated or the new branch to the remote branch.&lt;/li&gt;
&lt;li&gt;*&lt;em&gt;git pull  *&lt;/em&gt;: Used to update from the remote repository&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git revert &lt;/strong&gt; : Used to undo the modification related to specific commit.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Git merge
&lt;/h2&gt;

&lt;p&gt;git merge :Used to merge the current branch with the&lt;br&gt;
parent branch, with these steps :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;git checkout &lt;/strong&gt; : go to a specific branch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git fetch&lt;/strong&gt; : Update the specific branch&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;git merge &lt;/strong&gt; : Merging&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tips&lt;/strong&gt; :the best place to get more details about&lt;br&gt;
Git is documentation on the official website.&lt;br&gt;
It is advised to work with Git via the Git bash&lt;br&gt;
terminal . Every command mentioned up can&lt;br&gt;
be used with many tags.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to upload files with multer in your MERN App</title>
      <dc:creator>Yessine Agrebi</dc:creator>
      <pubDate>Wed, 27 Jul 2022 15:07:58 +0000</pubDate>
      <link>https://forem.com/yessine-agrebi/how-to-upload-files-with-multer-in-your-mern-app-jbg</link>
      <guid>https://forem.com/yessine-agrebi/how-to-upload-files-with-multer-in-your-mern-app-jbg</guid>
      <description>&lt;p&gt;File upload is a common operation for any applications. In Node.js, with the Express web framework and the Multer library, adding file upload feature to your app is very easy. In this tutorial, we are going to learn how to upload files on the server with the help of Multer and Express in Node.js and display it in React App. At the end of this blog, you will be able to integrate the file uploads in your own apps.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is Multer?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files. It is written on top of the busyboy, for maximum efficiency. By this, you can understand that multer is used to handle multipart/form-data.&lt;br&gt;
**&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Multipart Data?
&lt;/h2&gt;

&lt;p&gt;**&lt;br&gt;
When a “form” is submitted, browsers use “application-xx-www-form-urlencoded” content-type. This type contains only a list of keys and values and therefore are not capable of uploading files. Whereas, when you configure your form to use “multipart/form-data” content-type, browsers will create a “multipart” message where each part will contain a field of the form. A multipart message will consist of text input and file input. This way using multipart/form-data you can upload files.&lt;/p&gt;

&lt;p&gt;Multer adds a body object and a file or files object to the request object. The body object contains the values of the text fields of the form, the file or files object contains the files uploaded via the form.&lt;/p&gt;

&lt;p&gt;Multer will not process any form which is not multipart (multipart/form-data).&lt;br&gt;
Now Let's dive into the code..&lt;br&gt;
First of all you need to install multer in your Node.js app following this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//installation of multer module
npm install multer --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in this project we will store files into a folder named "images" in the "public" folder.&lt;br&gt;
We will create a files named "upload.js" (named as you like) and load multer in it, i'm using the import method if you work with require feel free.&lt;br&gt;
&lt;code&gt;import multer from 'multer';&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;DiskStorage&lt;/strong&gt;&lt;br&gt;
The disk storage engine gives you full control over storing files to disk. We will create a storage object using the diskStorage() method.&lt;br&gt;
The following code will go in &lt;strong&gt;upload.js&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;const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, './public/images');
    },
    filename: function (req, file, cb) {
        cb(null, Date.now() + "--" + file.originalname);
    }
});  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two properties, destination, and filename. They both are functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;destination&lt;/strong&gt; - It can also be given as a string (e.g. './public/images'). If no &lt;strong&gt;destination&lt;/strong&gt; is given, the operating system's default directory for temporary files is used. It is mandatory to create a directory when you are using destination as a function. Otherwise, if you are using destination as a string, multer will make sure that the directory is created for you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;filename&lt;/strong&gt; - It is used to determine what the file should be named inside the folder. If you don't provide any filename, each file will be given a random name without any file extension. It is your responsibility to provide a function that should return a complete filename with a file extension. Both these functions take 3 arguments - the request object, the file object and a callback function (here, cb is callback function). The 2 arguments to cb are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;null&lt;/strong&gt; : as we don’t want to show any error.&lt;br&gt;
&lt;strong&gt;file.originalname&lt;/strong&gt;: the name of the files where they are uploaded. &lt;br&gt;
We are going to use &lt;code&gt;Date.now() + "--" + file.originalname&lt;/code&gt; &lt;br&gt;
to make sure the uniqueness of the files names.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let upload = multer({ 
storage: storage,
 limits : {fileSize : 3000000
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we have called the &lt;strong&gt;multer() **method. It accepts an options object, with storage property, which tells Multer where to upload the files . and **limits&lt;/strong&gt; (it's an option not mandatory) to limit the fileSize. (1000000 bytes = 1mb).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Other Options:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;fileFilter&lt;/strong&gt; - Set this to a function to control which files should be uploaded and which should be skipped. The function should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fileFilter = (req, file, cb) =&amp;gt; {
    if((file.mimetype).includes('jpeg') || (file.mimetype).includes('png') || (file.mimetype).includes('jpg')){
        cb(null, true);
    } else{
        cb(null, false);
    }
};

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;export default upload.single('file-demo')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;.single() is used for uploading a single file.&lt;/p&gt;

&lt;p&gt;Note that the field name that you are providing in form data should be the same as the one provided in the &lt;strong&gt;multer({..}).single()&lt;/strong&gt; (here the name is file-demo)&lt;/p&gt;

&lt;p&gt;We have to export default the &lt;strong&gt;upload&lt;/strong&gt; to use it as a middleware in the routes.&lt;br&gt;
No go to the &lt;strong&gt;routes&lt;/strong&gt; folder 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 upload from "./upload.js";
const router = express.Router();
router.post('/', upload, (req, res) =&amp;gt; {
   const file = req.file.filename;
   const newImage = {file-demo : file}
   try{
     await newImage.save();
     res.status(201).json(newimage );
   }catch(error){
     res.status(409).json({ message: error.message });
   }

});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to display the images in your react app use the following :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// the url of your api following /public/images/
const url_imgs = "http://localhost:3001/public/images/"
&amp;lt;img
   src={`${url_imgs}${demo-file}`}
   alt=""
   /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we know how to integrate file upload using multer in any application. Go ahead! make your own application with complete frontend and integrate the file upload by using the above-acquired knowledge.&lt;/p&gt;

&lt;p&gt;Don't Stop Learning! &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>node</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
