<?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: Sarah Hassan</title>
    <description>The latest articles on DEV Community by Sarah Hassan (@sarah27h).</description>
    <link>https://dev.to/sarah27h</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%2F253952%2F81a6ac7c-b071-4088-a962-0679718106d4.jpeg</url>
      <title>DEV Community: Sarah Hassan</title>
      <link>https://dev.to/sarah27h</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sarah27h"/>
    <language>en</language>
    <item>
      <title>Download Bootstrap 5 using npm</title>
      <dc:creator>Sarah Hassan</dc:creator>
      <pubDate>Sun, 17 Oct 2021 22:56:25 +0000</pubDate>
      <link>https://dev.to/sarah27h/download-bootstrap-5-using-npm-2o0l</link>
      <guid>https://dev.to/sarah27h/download-bootstrap-5-using-npm-2o0l</guid>
      <description>&lt;p&gt;Today I will list steps needed to download Bootstrap 5 using npm.&lt;/p&gt;

&lt;p&gt;1- Install &lt;code&gt;Bootstrap&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install bootstrap&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;2- Use &lt;code&gt;Bootstrap&lt;/code&gt;:&lt;br&gt;
You have 2 options to import Bootstrap's JS.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Option 1:&lt;/em&gt;&lt;br&gt;
import all of Bootstrap’s plugins so you will not need &lt;code&gt;@popperjs/core&lt;/code&gt; package&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import '../../node_modules/bootstrap/dist/js/bootstrap.bundle.min.js';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Option 2:&lt;/em&gt;&lt;br&gt;
Import just plugins you need. Then you will need to install and import &lt;code&gt;@popperjs/core&lt;/code&gt; package before import bootstrap plugins&lt;/p&gt;

&lt;p&gt;a- Install &lt;code&gt;@popperjs/core&lt;/code&gt; package.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i @popperjs/core&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;b- In your app.js file import bootstrap and @popperjs/core.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import '../../node_modules/@popperjs/core/dist/umd/popper.min.js';

import 'bootstrap/js/dist/dropdown';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;c- Import Bootstrap's CSS.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@import "bootstrap/scss/bootstrap";&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

</description>
      <category>bootstrap</category>
      <category>beginners</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Compile and Bundle Javascript es6 with Browserify + Babelify + Gulp</title>
      <dc:creator>Sarah Hassan</dc:creator>
      <pubDate>Fri, 05 Mar 2021 15:37:06 +0000</pubDate>
      <link>https://dev.to/sarah27h/compile-and-bundle-javascript-es6-with-browserify-babelify-gulp-59e8</link>
      <guid>https://dev.to/sarah27h/compile-and-bundle-javascript-es6-with-browserify-babelify-gulp-59e8</guid>
      <description>&lt;p&gt;My story began while I was trying to use the &lt;code&gt;tiny slider&lt;/code&gt; npm package in my project and I used Gulp as my task runner.&lt;/p&gt;

&lt;p&gt;I got an error when I tried to import the &lt;code&gt;tiny slider&lt;/code&gt; js file in the script file of my project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// my gulp file
const { src, dest } = require('gulp');
// minify JS
const uglify = require('gulp-uglify');
// support JS for old browsers
const babel = require('gulp-babel');
// create source map files to JS
const sourcemaps = require('gulp-sourcemaps');
// rename files
const rename = require('gulp-rename');
const replace = require('gulp-replace');

const srcFiles = {
  jsPath: 'src/js/**/*.js'
};

const distFiles = {
  distJSPath: 'dist/js',
};

// my js task
function jsTask() {
  return (
    src([srcFiles.jsPath])
      // To load existing source maps
      // This will cause sourceMaps to use the previous sourcemap to create an ultimate sourcemap
      .pipe(gulpif(!production, sourcemaps.init({ loadMaps: true })))
      .pipe(
        gulpif(
          production,
          babel({
            presets: ['@babel/preset-env'],
          })
        )
      )
      .pipe(concat('all.js'))
      .pipe(gulpif(production, rename({ extname: '.min.js' })))
      .pipe(gulpif(production, uglify()))
      .pipe(gulpif(!production, sourcemaps.write('./')))
      .pipe(dest(distFiles.distJSPath))
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// my script file
import { tns } from '../../node_modules/tiny-slider/src/tiny-slider';

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

&lt;/div&gt;



&lt;p&gt;I got these errors:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Uncaught SyntaxError: Cannot use import statement outside a module&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GET http://localhost:3000/node_modules/tiny-slider/src/tiny-slider net::ERR_ABORTED 404 (Not Found)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's start to explain what is the problem then we learn to solve it.&lt;/p&gt;

&lt;p&gt;I used &lt;code&gt;gulp-babel&lt;/code&gt; to compile ES6 to ES5. The problem is that &lt;code&gt;require&lt;/code&gt; is not defined in the browser and in the ES5 syntax. So we need to search for another method to bundle all required js modules into one file.&lt;/p&gt;

&lt;p&gt;We need this &lt;code&gt;Browserify + Babelify&lt;/code&gt; combination to Compile &amp;amp; Bundle.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Browserify&lt;/code&gt; bundles js modules into one file to be used in the browser.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;'gulp-babel' didn't match with &lt;code&gt;Browserify&lt;/code&gt; so, we will use &lt;code&gt;Babelify&lt;/code&gt; instead to convert ES6 to ES5.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Steps are as 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;npm i --save-dev browserify

npm i --save-dev  babelify

// has all packages needed for babelify to work
npm i --save-dev @babel/core

// to tap the specific preset to compile our script
npm i --save-dev @babel/preset-env


// grab source after bundling of browserify and check if entry source is still piped.
npm i --save-dev vinyl-source-stream

// to continue with using source map and uglify
npm i --save-dev vinyl-buffer

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

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;package.json&lt;/code&gt;, We need to specify the &lt;code&gt;preset&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"devDependencies": {
    "@babel/core": "^7.13.8",
    "@babel/preset-env": "^7.9.6",
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.7.0",
    "babelify": "^8.0.0",
    "browser-sync": "^2.26.7",
    "browserify": "^17.0.0",
    .......
  },
  "babel": {
    "presets": [
      "@babel/preset-env"
    ]
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In gulp file:&lt;/p&gt;

&lt;p&gt;We can run js task for each group of files separately ex: a script for front-end and script for back-end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// define entry for browserify
const jsSrc = 'module.js';
const jsFolder = 'src/js/';

// we can add a script for front-end and script for back-end and so on
const jsFiles = [jsSrc];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const srcFiles = {
  jsPath: 'src/js/**/*.js',
  jsFiles: 'src/js/',
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');

async function jsTask() {
  jsFiles.map(function (entry) {
    return (
      browserify({
        entries: [jsFolder + entry],
      })
        .transform(babelify, { presets: ['@babel/preset-env'] })
        .bundle()
        .pipe(source('all.js'))
        // To load existing source maps
        // This will cause sourceMaps to use the previous sourcemap to create an ultimate sourcemap
        .pipe(gulpif(production, rename({ extname: '.min.js' })))
        .pipe(buffer())
        .pipe(gulpif(!production, sourcemaps.init({ loadMaps: true })))
        // .pipe(concat('all.js'))
        .pipe(gulpif(production, uglify()))
        .pipe(gulpif(!production, sourcemaps.write('./')))
        .pipe(dest(distFiles.distJSPath))
    );
  });
}

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

&lt;/div&gt;



&lt;p&gt;Resources that help me to solve the problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/@hey.aaron/getting-import-export-working-es6-style-using-browserify-babelify-gulp-5hrs-of-life-eca7786e44cc"&gt;Getting import/export working ES6 style using Browserify + Babelify + Gulp = -5hrs of life&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=ax0ykSVPufs"&gt;Gulp from Scratch: Compile and Bundle Javascript es6 with Babel&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope this article helps, feel free to share it with your friends, any feedback will be appreciated :)&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>gulp</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>html</category>
    </item>
    <item>
      <title>Improve website performance by optimizing HTML with gulp 4 &amp; browser-sync</title>
      <dc:creator>Sarah Hassan</dc:creator>
      <pubDate>Thu, 26 Nov 2020 00:51:43 +0000</pubDate>
      <link>https://dev.to/sarah27h/improve-website-performance-by-optimizing-html-with-gulp-4-browsersync-1844</link>
      <guid>https://dev.to/sarah27h/improve-website-performance-by-optimizing-html-with-gulp-4-browsersync-1844</guid>
      <description>&lt;p&gt;Today I will explain how to optimize HTML files reduce their sizes as possible.&lt;br&gt;
We can achieve that by doing 3 things first &lt;code&gt;minifying&lt;/code&gt; then &lt;code&gt;compressing&lt;/code&gt; finally &lt;code&gt;cache them&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;First, let me explain the difference between &lt;code&gt;minify&lt;/code&gt; and &lt;code&gt;compress&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Minify&lt;/code&gt;: remove white spaces, comments, and unnecessary characters.&lt;/li&gt;
&lt;li&gt;while &lt;code&gt;compressing&lt;/code&gt;: the process of reducing the size of data (encoding information) using algorithms to compress ex gzip, deflate.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  What happens between server and browser?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;browser request index.html file.&lt;/li&gt;
&lt;li&gt;server sends a &lt;code&gt;.zip&lt;/code&gt; file to the browser &lt;code&gt;(index.html.zip)&lt;/code&gt; instead of the regular &lt;code&gt;index.html&lt;/code&gt; version.&lt;/li&gt;
&lt;li&gt;The browser then downloads the &lt;code&gt;zipped file&lt;/code&gt;, extracts it, and then shows it to the user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;but how server know it’s OK to send the zipped one and not the regular index file???&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;They have an agreement with 2 parts:&lt;/p&gt;

&lt;p&gt;1 -The browser sends a header telling the server it accepts compressed content (gzip and deflate are two compression schemes): Accept-Encoding: gzip, deflate&lt;/p&gt;

&lt;p&gt;2- The server sends a response if the content is actually compressed: Content-Encoding: gzip&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For more info read this &lt;a href="https://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/"&gt;great article&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I'm using gulp 4 as a task runner and browser-sync. So we will need the following packages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/gulp-htmlmin"&gt;gulp-htmlmin&lt;/a&gt; to minify html files.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/gulp-gzip"&gt;gulp-gzip&lt;/a&gt; to compress html files.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/connect-gzip-static"&gt;connect-gzip-static&lt;/a&gt; to enable us serve zipped HTML in local server for testing during dev.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  a- &lt;code&gt;minifying&lt;/code&gt;:
&lt;/h3&gt;

&lt;p&gt;1- install with npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save gulp-htmlmin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2- create &lt;code&gt;minifyIndex&lt;/code&gt; task to minify &lt;code&gt;index&lt;/code&gt; set options like remove comments and whitespace.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function minifyIndex() {
  return src('./index.html')
    .pipe(htmlmin({ collapseWhitespace: true, removeComments: true }))
    .pipe(dest('dist/'));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  b- &lt;code&gt;compressing&lt;/code&gt;:
&lt;/h3&gt;

&lt;p&gt;1- install with npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev gulp-gzip connect-gzip-static

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

&lt;/div&gt;



&lt;p&gt;2- create &lt;code&gt;compressIndex&lt;/code&gt; task to compress &lt;code&gt;index&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function compressIndex() {
  return src('./index.html')
    .pipe(gzip())
    .pipe(dest('dist/'));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3- serve compressed files for the local server &lt;br&gt;
I tried to use the following method but it failed as middleware is too late in the stack when added via the options for .html files so the server didn't serve our zipped file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const compression= require('compression');

browserSync({
    server: {
        baseDir: './',
        middleware: [compression()]
    }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;adding override boolean will cause this middleware to be applied to the FRONT of the stack as mentioned by Shane Osbourne &lt;a href="https://github.com/BrowserSync/recipes/issues/4#issuecomment-252511287"&gt;here&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function serveTask() {
  // init browserSync
  browserSync.init({
    // setup server
    server: {
      baseDir: './dist/',
    },
    middleware: [
      {
        route: '', // empty 'route' will apply this to all paths
        handle: gzipStatic('./dist/'), // the callable
        override: true,
      },
    ],
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: you need also to add the regular index version as a fallback in case the server doesn’t send the content-encoding response header, which means the file is not compressed (the default on many servers).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function initIndexHtml() {
  return src('./index.html')
    .pipe(htmlmin({ collapseWhitespace: true, removeComments: true }))
    .pipe(dest('dist/'));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after doing html optimization in my project I succeeded in reducing index file size from &lt;code&gt;21kb&lt;/code&gt; to &lt;code&gt;3.5kb&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Test if the compressed content is served:
&lt;/h3&gt;

&lt;p&gt;1- open your site and developer tools.&lt;/p&gt;

&lt;p&gt;2- open network tab check use large request rows to be able view size before and after optimization.&lt;/p&gt;

&lt;p&gt;3- reload.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wkr0TwGn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cy7zj5u1nmwunupmdcff.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wkr0TwGn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cy7zj5u1nmwunupmdcff.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GJSGGwOg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/omwhi5s6yfo91pfb1ew2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GJSGGwOg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/omwhi5s6yfo91pfb1ew2.png" alt="Alt image show how optimization reduce file size"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4- click as shown to display headers and response header &lt;code&gt;'Content-encoding: gzip'&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xu8eyxgn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5n9yc6c8lb5aho4kzj2n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xu8eyxgn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5n9yc6c8lb5aho4kzj2n.png" alt="Alt image show response header"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

&lt;p&gt;Hope this article helps, feel free to share it with your friends, any feedback will be appreciated :)&lt;/p&gt;

</description>
      <category>html</category>
      <category>gulp</category>
      <category>beginners</category>
      <category>performance</category>
    </item>
    <item>
      <title>localhost + service worker &amp; caches = serve old app</title>
      <dc:creator>Sarah Hassan</dc:creator>
      <pubDate>Thu, 24 Sep 2020 20:44:16 +0000</pubDate>
      <link>https://dev.to/sarah27h/localhost-service-worker-caches-serve-old-app-4bg</link>
      <guid>https://dev.to/sarah27h/localhost-service-worker-caches-serve-old-app-4bg</guid>
      <description>&lt;p&gt;I will share with you an issue that occurred while I was developing a new app. When I try to open the new app with the localhost at the port 3000 it always opens the old app :(&lt;/p&gt;

&lt;p&gt;You can imagine what I felt, stop the server, and then start again many times and I couldn't believe why the old app continuously appears???&lt;/p&gt;

&lt;p&gt;I googled for a solution to kill that old app.&lt;/p&gt;

&lt;p&gt;My Sincere friend StackOverflow help me, please then I found a &lt;a href="https://stackoverflow.com/questions/39632667/how-do-i-kill-the-process-currently-using-a-port-on-localhost-in-windows"&gt;solution&lt;/a&gt;. Open cmd and &lt;code&gt;run netstat -ano | findstr :&amp;lt;PORT&amp;gt;&lt;/code&gt; and then a list will appear and you can kill it by &lt;code&gt;run taskkill /PID &amp;lt;PID&amp;gt; /F&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Wow, I killed it. let's try to open our new app in confidence. What???? No, the old app is still alive :(&lt;/p&gt;

&lt;p&gt;I tried many other solutions but it is still alive!&lt;/p&gt;

&lt;p&gt;Take a breathe and think and think again and suddenly I asked myself what weapons the old app had to beat me in this game?? The old app is a weather app with a manifest file and service worker and cachhhhe. I google again and found &lt;a href="https://stackoverflow.com/questions/47953491/chrome-loading-cached-files-on-localhost"&gt;this solution&lt;/a&gt;. Now -a loud hahaha- I know how to kill it :D&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tvsu9IIi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/avliwksofqehjd6pxaij.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tvsu9IIi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/avliwksofqehjd6pxaij.png" alt="Game over by Darius Dan Blue&amp;lt;br&amp;gt;
 from flaticon"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just by clearing storage from developer tools. What caused the issue is that chrome was loading cached files for the old app. So every time I tried to open at the port 3000 it was opened from caches.&lt;/p&gt;

&lt;p&gt;Thanks for reading! If you meet a similar issue leave a comment and share how you did solve it.&lt;/p&gt;

&lt;p&gt;Don't forget to follow me to get real programming problems that you may face and get solutions for them.&lt;/p&gt;

&lt;p&gt;Hope this article helps, feel free to share it with your friends, any feedback will be appreciated :)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>localhost</category>
      <category>cache</category>
    </item>
    <item>
      <title>Font Awesome 5 with Using a Package Manager + using Gulp 4</title>
      <dc:creator>Sarah Hassan</dc:creator>
      <pubDate>Tue, 04 Aug 2020 01:27:54 +0000</pubDate>
      <link>https://dev.to/sarah27h/install-font-awesome-5-with-using-a-package-manager-and-use-it-with-gulp-5gi8</link>
      <guid>https://dev.to/sarah27h/install-font-awesome-5-with-using-a-package-manager-and-use-it-with-gulp-5gi8</guid>
      <description>&lt;p&gt;In this article, we will learn how to add Font Awesome 5 by using the package manager and gulp 4.&lt;/p&gt;

&lt;p&gt;1- Install Font Awesome using a Package Manager&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save @fortawesome/fontawesome-free&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or &lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn add --dev @fortawesome/fontawesome-free&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2- Import Font Awesome in you main SCSS file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// in your main SCSS file
@import '../../node_modules/@fortawesome/fontawesome-free/scss/fontawesome.scss';

// import one or more styles
@import '../../node_modules/@fortawesome/fontawesome-free/scss/regular.scss';
@import '../../node_modules/@fortawesome/fontawesome-free/scss/solid.scss';
@import '../../node_modules/@fortawesome/fontawesome-free/scss/brands.scss';

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important Tip:&lt;/strong&gt; &lt;em&gt;to avoid getting blank squares for font awesome icons you need adding those files&lt;code&gt;otf | ttf | eot | svg | woff(2)&lt;/code&gt; and they are in &lt;code&gt;webfonts&lt;/code&gt; folder&lt;br&gt;
you need to make sure &lt;code&gt;webfonts&lt;/code&gt; folder and &lt;code&gt;index.html&lt;/code&gt; are in your &lt;code&gt;dist&lt;/code&gt; folder of production version&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Qp7abSd4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bt61uner64s3f5rqe7a8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Qp7abSd4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bt61uner64s3f5rqe7a8.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3- Check if &lt;code&gt;webfonts&lt;/code&gt; folder exists then make a copy in dist by using any file in the webfonts folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;We need to pass a path for a file, not a folder because in &lt;a href="https://www.npmjs.com/package/file-exists"&gt;docs&lt;/a&gt; of package was mentioned that:&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The package used to check if filepath exists and is a file. Returns false for directories.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will use &lt;a href="https://www.npmjs.com/package/file-exists"&gt;&lt;code&gt;file-exists&lt;/code&gt;&lt;/a&gt; package to check if &lt;code&gt;webfonts&lt;/code&gt; exists then make a copy of &lt;code&gt;webfonts&lt;/code&gt; and put in the &lt;code&gt;dist folder&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// in your gulpfile
const fileExists = require('file-exists');
const gulpif = require('gulp-if');

const webFontsPath= './node_modules/@fortawesome/fontawesome-free/webfonts/*';
const distWebfonts= 'dist/webfonts';

// use a file of webfonts to check it's existing then make a copy in dist
const fontawesomeWebfont =
  './node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands-400.eot';

// to check if file exists or not for testing purposes
console.log(fileExists.sync(fontawesomeWebfont)); // OUTPUTS: true or false

// copy webfonts folder if it exists
// because our task contains asynchronous code
// use async before our task
// to avoid getting this error `Did you forget to signal async completion`
async function copyfontawesomeWebfontsTask() {
  return gulpif(
    fileExists.sync(fontawesomeWebfont),
    src([webFontsPath]).pipe(dest(distWebfonts))
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wow, now you can use copyfontawesomeWebfontsTask :)&lt;/p&gt;

&lt;p&gt;Thanks for reading! I know there are many methods to do that but this method worked for me and like to share with you. &lt;br&gt;
Hope this article helps, feel free to share it with your friends, any feedback will be appreciated :)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>npm</category>
      <category>saas</category>
      <category>gulp</category>
    </item>
    <item>
      <title>How to solve index conflicts when we remove indexes in random order from an array?</title>
      <dc:creator>Sarah Hassan</dc:creator>
      <pubDate>Thu, 12 Mar 2020 18:26:26 +0000</pubDate>
      <link>https://dev.to/sarah27h/how-to-solve-index-conflicts-when-we-remove-indexes-in-random-order-from-an-array-4agf</link>
      <guid>https://dev.to/sarah27h/how-to-solve-index-conflicts-when-we-remove-indexes-in-random-order-from-an-array-4agf</guid>
      <description>&lt;p&gt;There are a lot of ways to remove items from an array. Today, I will discuss with you the index conflict problem that I faced while I was building my last app and how I solved it. I had an array of indexes that I should remove from the student data array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// indexes to remove from the student data array
const selectedIndexs = [0, 3, 1];
const studentData = [
 {name:'Alice',attendanceDays:[false,true, …]},
 {name:'Lydia',attendanceDays:[false,true, …]},
 {name:'Mike',attendanceDays:[true,false, …]},
 {name:'Harry',attendanceDays:[false,true, …]},
 {name:'Julie',attendanceDays:[true,false, …]}
];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The selectedIndexs were in random order when I deleted the item in index 0 from studentData. The remaining items in studentData were shifted and this result in index conflict and removing unwanted students.&lt;br&gt;
Let’s simplify the code and get to our main point, how to remove random indexes from an array? Say, I have an array of student names.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const studentNames = ['Alice', 'Lydia', 'Mike', 'Harry', 'Julie'];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Suppose I have another array containing student’s indexes we want to remove. (students at indexes 0, 2)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const selectedIndexs = [0, 4, 2] //  which refer to 'Alice', 'Julie' and 'Mike'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sJI0kkZC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2x6x7ijx2krowvt7dkf4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sJI0kkZC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2x6x7ijx2krowvt7dkf4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I had first thought to use iterate over selectedIndexs array using forEach and then I used the splice method to remove each studentIndex from studentNames array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;selectedIndexs.forEach( studentIndex =&amp;gt; studentNames.splice(studentIndex, 1));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;First, the student at index 0 from studentNames array will be removed and the array will be &lt;code&gt;[ 'Lydia', 'Mike', 'Harry', 'Julie']&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7KUV1Xwe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nzlscux78mf5c2mob0tl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7KUV1Xwe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nzlscux78mf5c2mob0tl.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then the student at index 4 will be removed, but there isn’t a student at index 4 because indexes have been shifted and so the array will be as it is &lt;code&gt;[ 'Lydia', 'Mike', 'Harry', 'Julie']&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1eCh65_4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tb2ezkrkcjzsgyac3r7o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1eCh65_4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tb2ezkrkcjzsgyac3r7o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, the student at index 2 will be removed and the array will be &lt;code&gt;[ 'Lydia', 'Mike', 'Julie']&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eta14A8x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/c9t1jdtxaxbhd85q6nxs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eta14A8x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/c9t1jdtxaxbhd85q6nxs.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What ???&lt;/p&gt;

&lt;p&gt;Can you guess what’s happened here?&lt;/p&gt;

&lt;p&gt;I want to remove &lt;code&gt;['Alice', 'Julie' and 'Mike']&lt;/code&gt; but instead of that &lt;code&gt;'Alice'&lt;/code&gt;, 'Harry' were removed.&lt;br&gt;
As you know the splice method manipulates the original array and does not return a new array. This is what happened in our example, the splice method changed the studentNames and that was the cause of the index conflict.&lt;br&gt;
How to solve this issue? A good practice to follow when we want to remove items from an array is to start from the last index. Suppose if we want to remove array items in a random order then we need to sort indexes in descending order using the sort method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//sort method will return [4, 2, 0]
//splice method will first remove student at index 4 then at index 2 and finally at index 0 and return ['Lydia', 'Harry']
selectedIndexs.sort((a,b) =&amp;gt; a &amp;gt; b? -1 : 1).forEach( studentIndex =&amp;gt; studentNames.splice(studentIndex, 1))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Student at index 4 first will be removed then will be removed student at index 2 and lastly the student at index 0 will be removed and studentNames will be &lt;code&gt;['Lydia', 'Harry']&lt;/code&gt;. This approach ensures that we remove from the last index to avoid index conflict.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AXd1p15P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/py6uehgpj49jp5tlihm7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AXd1p15P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/py6uehgpj49jp5tlihm7.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conclusion: 'If you want to remove items from an array in a random order you need to sort indexes in descending order first'.&lt;/p&gt;

&lt;p&gt;Hope this helps, your feedback will be appreciated. Thanks for reading!&lt;br&gt;
Resources:&lt;/p&gt;

&lt;p&gt;MDN Docs: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice"&gt;Array.prototype.splice()&lt;/a&gt;&lt;br&gt;
MDN Docs: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort"&gt;Array.prototype.sort()&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Attribution:  Images made by Freepik from &lt;a href="https://www.flaticon.com/"&gt;flaticon&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>arrays</category>
      <category>index</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to mask your API key?</title>
      <dc:creator>Sarah Hassan</dc:creator>
      <pubDate>Mon, 02 Mar 2020 16:27:44 +0000</pubDate>
      <link>https://dev.to/sarah27h/how-to-mask-your-api-key-249e</link>
      <guid>https://dev.to/sarah27h/how-to-mask-your-api-key-249e</guid>
      <description>&lt;p&gt;Your API key should remain private and to achieve that Git should not track the API key. So today I will talk about two ways for masking API key, suppose you are developing a new app using React.js and have an API key to fetch news.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First one, using the environment variable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- Create a file called &lt;code&gt;.env&lt;/code&gt; in the project directory and define a variable with uppercase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;REACT_APP_NEWS_KEY = 'your_API_key'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;2- Ignore &lt;code&gt;.env&lt;/code&gt; file by adding its name to &lt;code&gt;.gitignore&lt;/code&gt; file. The purpose of &lt;code&gt;.gitignore&lt;/code&gt; file is to ensure that certain files not tracked by Git.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# api keys
.env
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;3- Access API key in your project using process.env.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const API_KEY = process.env.REACT_APP_NEWS_KEY;

const getPosts = async () =&amp;gt; {
    try {
      dispatch({ type: 'SEND_REQUEST' });
      const response = await fetch(
        `https://newsapi.org/v2/everything?q=javascript&amp;amp;apiKey=${API_KEY}`
      );
      const data = await response.json();
      dispatch({ type: 'REQUEST_FINISH' });
      dispatch({ type: 'SET_POSTS', payload: data });
    } catch (err) {
      console.log(err);
    }
  };
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Important Note: After creating the environment variable you have to restart your server to avoid getting &lt;code&gt;your API key is invalid, you will receive a 401 - Unauthorized HTTP&lt;/code&gt; error.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second one, using named export&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1- Create a folder in &lt;code&gt;src&lt;/code&gt; folder called &lt;code&gt;config&lt;/code&gt; and inside it create a js file called &lt;code&gt;config.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const reactNewKey = 'your_API_key';

export { reactNewKey };
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;2-  Ignore &lt;code&gt;config.js&lt;/code&gt; file by adding its path in &lt;code&gt;.gitignore&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src/config/config.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;3- Acess API key in your project by importing it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { reactNewKey } from 'path_of_your_file'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Thanks for reading! I hope this article helps, feel free to share it with your friends, any feedback will be appreciated :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>api</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
