<?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: Stéphane Sulikowski</title>
    <description>The latest articles on DEV Community by Stéphane Sulikowski (@sulistef).</description>
    <link>https://dev.to/sulistef</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%2F341051%2Fbb803a14-1073-49ab-84a2-667bc13144ae.jpeg</url>
      <title>DEV Community: Stéphane Sulikowski</title>
      <link>https://dev.to/sulistef</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sulistef"/>
    <language>en</language>
    <item>
      <title>The Benefits of Pure Functions in JavaScript</title>
      <dc:creator>Stéphane Sulikowski</dc:creator>
      <pubDate>Thu, 03 Feb 2022 20:22:29 +0000</pubDate>
      <link>https://dev.to/sulistef/the-benefits-of-pure-functions-in-javascript-1d2b</link>
      <guid>https://dev.to/sulistef/the-benefits-of-pure-functions-in-javascript-1d2b</guid>
      <description>&lt;p&gt;What are pure functions ? In short, pure functions are functions that don’t modify the global state and don’t depend on any external input. They always return the same result when given the same input. This makes them predictable and reliable. In this blog post, we will discuss the benefits of using pure functions in JavaScript, and show you how to write your own!&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits
&lt;/h2&gt;

&lt;p&gt;One of the biggest benefits of using pure functions is that they are predictable and reliable. When you call a pure function, you can be sure that it will always return the same result, given the same input. This makes them perfect for use in libraries or frameworks, where you need to be able to count on their behavior. Pure functions are also easy to debug, since any errors will be caused by the function itself, and not by some external input.&lt;/p&gt;

&lt;p&gt;Another benefit of pure functions is that they are lightweight. They don’t require any special libraries or frameworks, and they can be executed in any environment. This makes them a great choice for small scripts or prototypes.&lt;/p&gt;

&lt;p&gt;Pure functions also have some performance benefits. Because they don’t modify the global state, they are faster than regular functions. They also use less memory, which is important for applications with large data sets.&lt;br&gt;
Finally, pure functions are simple and easy to understand. You don’t need to know anything about the internals of a function to use it correctly. This makes them ideal for beginners who are just learning JavaScript.&lt;/p&gt;
&lt;h2&gt;
  
  
  So, how can you write pure functions?
&lt;/h2&gt;

&lt;p&gt;It’s very easy! Just follow these simple steps:&lt;br&gt;
First, create a function that takes one input and returns a result.&lt;br&gt;
Next, make sure the function doesn’t modify the global state or depend on any external input.&lt;br&gt;
Finally, test the function to make sure it returns the same result every time.&lt;br&gt;
Here’s an example of a pure function in action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// return the sum of 2 numbers

const getSum = (a, b) =&amp;gt; {
  return a + b;
};

console.log(getSum(1, 2)); // returns 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And on the other hand, here is an example of an impure function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// return the sum of 2 numbers and add a parameter value

const addParameter = 3;

const getSumPlusParameter = (a, b) =&amp;gt; {
  return a + b + addParameter;
};

console.log(getSumPlusParameter(1, 2)); // returns 6 and depends of an external parameter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  When to use pure functions?
&lt;/h2&gt;

&lt;p&gt;When you need a function to always return the same result, given the same input. Pure functions are perfect for this purpose.&lt;/p&gt;

&lt;p&gt;When you’re writing a library or framework that will be used by other developers. Pure functions are the best way to ensure predictable and reliable behavior.&lt;br&gt;
When you’re learning JavaScript. Pure functions are simple and easy to understand, making them ideal for beginners.&lt;/p&gt;

&lt;h2&gt;
  
  
  And … when to use impure functions?
&lt;/h2&gt;

&lt;p&gt;When you need to call a function with side effects (such as modifying global state or accessing external resources)&lt;br&gt;
When the function is too complex to be written as a pure function&lt;/p&gt;

&lt;p&gt;When performance is more important than reliability or readability.&lt;/p&gt;

&lt;p&gt;Impure functions can be a bit more tricky to debug than pure functions, but they often have better performance. If you need to call a function with side effects, or if the function is too complex to be written as a pure function, then it’s best to use an impure function. Just make sure you test it thoroughly and be aware of any potential problems!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;When in doubt, use a pure function. Pure functions are easier to read and maintain, and they always return the same result.&lt;/p&gt;

&lt;p&gt;Use impure functions when you need to call a function with side effects, or when the function is too complex to be written as a pure function. Be aware of any potential problems that may arise.&lt;/p&gt;

&lt;p&gt;As you can see, using pure functions in JavaScript is a great way to improve reliability and performance while keeping things simple and easy to understand. So, next time you’re writing a script or prototype, be sure to use pure functions! They’ll make your code easier to read and maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can you do to help me?
&lt;/h2&gt;

&lt;p&gt;Please don’t hesitate to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Like the article&lt;/li&gt;
&lt;li&gt;Follow me&lt;/li&gt;
&lt;li&gt;Leave a comment and express your opinion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding! :)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why am I using Divi for WordPress ?</title>
      <dc:creator>Stéphane Sulikowski</dc:creator>
      <pubDate>Wed, 02 Feb 2022 10:19:14 +0000</pubDate>
      <link>https://dev.to/sulistef/why-am-i-using-divi-for-wordpress--3d5a</link>
      <guid>https://dev.to/sulistef/why-am-i-using-divi-for-wordpress--3d5a</guid>
      <description>&lt;p&gt;If you’re looking for an easy-to-use, fast, and beautiful WordPress theme, look no further than Divi. Created by the team at Elegant Themes, Divi is the perfect theme for anyone looking to create a stunning website without any coding required. In this blog post, we’ll take a look at the top benefits of using Divi for WordPress.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Divi is super easy to install. Simply download and activate the theme, and you’re ready to go. No coding is required!&lt;/p&gt;

&lt;h2&gt;
  
  
  Visual builder
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b1btvCTj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iuwwzxhbuykemcb71p6n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b1btvCTj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iuwwzxhbuykemcb71p6n.png" alt="Image description" width="700" height="398"&gt;&lt;/a&gt;&lt;br&gt;
The Divi visual builder is one of the theme’s standout features. With it, you can create beautiful designs with just a few clicks. Plus, you can see your changes in real-time, so there’s no need to wait for pages to reload.&lt;/p&gt;

&lt;h2&gt;
  
  
  Animations and effects
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RNNcwjD3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9f0d443kibtos318w6ip.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RNNcwjD3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9f0d443kibtos318w6ip.png" alt="Image description" width="700" height="398"&gt;&lt;/a&gt;&lt;br&gt;
Divi comes with many built-in animations and effects that you can use to make your website stand out. With Divi, you can create beautiful pages without having to rely on plugins or additional software.&lt;/p&gt;

&lt;h2&gt;
  
  
  Theme builder
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7dOEsNKQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6cusokvtcmgzwfutbyx2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7dOEsNKQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6cusokvtcmgzwfutbyx2.png" alt="Image description" width="700" height="403"&gt;&lt;/a&gt;&lt;br&gt;
Divi’s theme builder gives you complete control over your website’s design. With it, you can easily create custom header designs, footers, and more. You can also choose from a variety of different layouts and modules to create the perfect look for your website.&lt;br&gt;
The theme builder also allows you to export and import themes in a very easy way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Designs library
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LpoB7TdL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xk7q8ibb1lwpde7b8v7p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LpoB7TdL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xk7q8ibb1lwpde7b8v7p.png" alt="Image description" width="700" height="355"&gt;&lt;/a&gt;&lt;br&gt;
The Divi designs library is packed with beautiful templates to get you started. Plus, you can easily create your custom templates and save them for future use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Faster page load times
&lt;/h2&gt;

&lt;p&gt;Divi is also known for its fast page load times. This is thanks to the built-in caching system, which stores your pages and posts in a temporary storage area so they can be loaded quickly and easily.&lt;br&gt;
Fast development&lt;br&gt;
Divi is also one of the fastest WordPress themes around. This means that you can create beautiful websites in no time at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Customization
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jUu0wl51--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdat3nmcpzjmj1368zlm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jUu0wl51--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdat3nmcpzjmj1368zlm.png" alt="Image description" width="700" height="399"&gt;&lt;/a&gt;&lt;br&gt;
If needed, you can add your CSS classes to fine-tune your design with the advanced tools&lt;br&gt;
Export/import&lt;br&gt;
The Divi theme also includes an export/import feature, which makes it easy to move your website from one server to another.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stability
&lt;/h2&gt;

&lt;p&gt;Divi is also a very stable WordPress theme. It has been tested on thousands of websites and has never caused any problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Updates
&lt;/h2&gt;

&lt;p&gt;Divi is regularly updated with new features and enhancements, so you can be sure that your website will always be up-to-date.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pricing
&lt;/h2&gt;

&lt;p&gt;Unlike some other WordPress themes, Divi is affordable and costs just $89 for access to all of its features. This makes it a great option for small businesses, bloggers, and anyone else who wants to create a professional website without spending a lot of money.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As you can see, the Divi theme offers a ton of features and benefits that make it the perfect choice for WordPress users of all levels of experience. And there would be a lot more to say about it! It saved me a ton of time during my blog development and I was astonished by the endless possibilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can you do to help me?
&lt;/h2&gt;

&lt;p&gt;Please don’t hesitate to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Like the article&lt;/li&gt;
&lt;li&gt;Follow me&lt;/li&gt;
&lt;li&gt;Leave a comment and express your opinion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy no-coding!&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>divi</category>
    </item>
    <item>
      <title>How to set up routing in an Express.js project using TypeScript</title>
      <dc:creator>Stéphane Sulikowski</dc:creator>
      <pubDate>Wed, 26 Jan 2022 08:12:49 +0000</pubDate>
      <link>https://dev.to/sulistef/how-to-set-up-routing-in-an-expressjs-project-using-typescript-51ib</link>
      <guid>https://dev.to/sulistef/how-to-set-up-routing-in-an-expressjs-project-using-typescript-51ib</guid>
      <description>&lt;p&gt;This tutorial will go through the steps to set up routing with express.js and some best practices.&lt;br&gt;
This post follows the setup of the Express.js backend system described here: &lt;a href="https://dev.to/sulistef/how-to-set-up-a-nodejs-backend-using-expressjs-and-typescript-1655"&gt;How to set up a Node.js backend using Express.js and TypeScript&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is routing?
&lt;/h2&gt;

&lt;p&gt;A route is a system that associates an HTTP request and a function that will execute a process. There can be some parameters to handle, and the function can provide an answer to send back to the process requesting the route.&lt;br&gt;
How to create a simple route?&lt;/p&gt;

&lt;p&gt;In the index.tx file located in the src folder, we will add our first route :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.get('/', (req, res) =&amp;gt; {
    res.send("What's up doc ?!");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code means :&lt;br&gt;
the URL that will request the root route with a GET method will trigger a function that will send the message “What’s up doc ?!”&lt;/p&gt;

&lt;p&gt;Insert this code in the index.ts 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 express from 'express';
import dotenv from 'dotenv';

const app = express();
dotenv.config();

// routes
app.get('/', (req, res) =&amp;gt; {
  res.send("What's up doc ?!");
});

// start the server
app.listen(process.env.BACK_PORT, () =&amp;gt; {
  console.log(
    `server running : http://${process.env.BACK_HOST}:${process.env.BACK_PORT}`
  );
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and run the server with the terminal command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then with a web browser, enter the URL of the server. In my case : &lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt;&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%2F4tpfg1ppq8xzx144v038.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%2F4tpfg1ppq8xzx144v038.png" alt="Image description" width="511" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So now the root route “/” returns the message “What’s up doc ?!”&lt;/p&gt;

&lt;h2&gt;
  
  
  Manage routing in separate files
&lt;/h2&gt;

&lt;p&gt;We could handle all the routes in the main index.ts file and list all of them with the functions and processes, but splitting them into several files will help us have a more maintainable code.&lt;br&gt;
So in the src folder, let’s create a routes folder and a defaultRoute.ts file inside it.&lt;br&gt;
We will now declare the root route in defaultRoute.ts 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;import { Router } from 'express';

export const defaultRoute = Router();

defaultRoute.get('/', (req, res) =&amp;gt; {
  res.send("What's up doc ?!");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code looks very similar to the one we wrote in the index.ts&lt;/p&gt;

&lt;p&gt;Now, inside the routes filter, create an index.ts file that will gather all routes from the different files:&lt;br&gt;
import express from 'express';&lt;br&gt;
import { defaultRoute } from './defaultRoute';&lt;/p&gt;

&lt;p&gt;export const routes = express.Router();&lt;/p&gt;

&lt;p&gt;routes.use(defaultRoute);&lt;br&gt;
And finally, let’s update the src/index.ts to use these routes :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';
import dotenv from 'dotenv';
import { routes } from './routes';

const app = express();
dotenv.config();

// routes
app.use('/', routes);

// start the server
app.listen(process.env.BACK_PORT, () =&amp;gt; {
  console.log(
    `server running : http://${process.env.BACK_HOST}:${process.env.BACK_PORT}`
  );
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stop and run the server again to see that you have the same result as before.&lt;/p&gt;

&lt;p&gt;From here we can start building our routes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Route with process
&lt;/h2&gt;

&lt;p&gt;Let’s do something more funny: we will create a route that takes 2 numbers as parameters and return the sum.&lt;br&gt;
As we will expect some data, we will use the POST method and listen for the route /calc.&lt;br&gt;
First, in src/routes, we will create a calcRoute.ts with a new route listening for a post method on the /calc URL:&lt;br&gt;
import express, { Request, Response } from 'express';&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const calcRoute = express.Router();

calcRoute.post('/calc', (req: Request, res: Response) =&amp;gt; {

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

&lt;/div&gt;



&lt;p&gt;And now we add the process:&lt;br&gt;
check if both the parameters exist in the request body&lt;br&gt;
return the sum in a json format&lt;br&gt;
return an error in a json format if a parameter is missing or is not a number&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express, { Request, Response } from 'express';

export const calcRoute = express.Router();

calcRoute.post('/calc', (req: Request, res: Response): void =&amp;gt; {
  const { a, b } = req.body;

  if (a &amp;amp;&amp;amp; b &amp;amp;&amp;amp; typeof a === 'number' &amp;amp;&amp;amp; typeof b === 'number') {
    res.json({
      success: true,
      message: a + b,
    });
  } else {
    res.json({
      success: false,
      message: 'Missing parameters',
    });
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get this route properly working we need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;add it to the routes/index.ts
-install body-parser to get the parameters from the request&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Adding the route
&lt;/h3&gt;

&lt;p&gt;In the src/routes/index.ts we will add the new route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';
import { calcRoute } from './calcRoute';
import { defaultRoute } from './defaultRoute';

export const routes = express.Router();

routes.use(defaultRoute);
routes.use(calcRoute);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Installing and setup body-parser
&lt;/h3&gt;

&lt;p&gt;In the terminal, let’s install the library&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 body-parser --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the src/index.ts we will set it up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import express from 'express';
import { Application } from 'express';
import dotenv from 'dotenv';
import { routes } from './routes';
import bodyParser from 'body-parser';

const app: Application = express();

// body-parser
app.use(bodyParser.json({ limit: '50mb', type: 'application/json' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
dotenv.config();

// routes
app.use('/', routes);

// start the server
app.listen(process.env.BACK_PORT, () =&amp;gt; {
  console.log(
    `server running : http://${process.env.BACK_HOST}:${process.env.BACK_PORT}`
  );
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Test the route
&lt;/h3&gt;

&lt;p&gt;To test this route we will need a software like postman to send the request with the parameters in the body after restarting the server:&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%2Fcekbl4xcqnrizipicj34.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%2Fcekbl4xcqnrizipicj34.png" alt="Image description" width="800" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;We looked at how to route and handle them in distinct files in this brief example. There’s still much more to say about routes, particularly when it comes to more complicated use cases and the use of middlewares to manage processes.&lt;/p&gt;

&lt;p&gt;After reading this document, I hope you will have a clear understanding of the basics of express.js’s routing system.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can you do to help me?
&lt;/h2&gt;

&lt;p&gt;Please don’t hesitate to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Like the article&lt;/li&gt;
&lt;li&gt;Follow me&lt;/li&gt;
&lt;li&gt;Leave a comment and express your opinion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why I use VSCode as an IDE</title>
      <dc:creator>Stéphane Sulikowski</dc:creator>
      <pubDate>Tue, 25 Jan 2022 17:39:34 +0000</pubDate>
      <link>https://dev.to/sulistef/why-i-use-vscode-as-an-ide-33jk</link>
      <guid>https://dev.to/sulistef/why-i-use-vscode-as-an-ide-33jk</guid>
      <description>&lt;p&gt;I have been a VSCode user for some time now and I am very happy with the decision. The benefits that VSCode has to offer are so many it is hard to list them all in one post, but here are just a few of the reasons why VSCode is my IDE of choice.&lt;/p&gt;

&lt;p&gt;VSCode is my go-to IDE because it offers a great user experience, cross platform support, and tons of integrations. VSCode has quickly become one of the most popular IDEs out there, and for good reason!&lt;/p&gt;

&lt;p&gt;Here are some more reasons why VSCode is a great choice for me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It runs on Windows, MacOS, Linux … and recently in a web browser&lt;/li&gt;
&lt;li&gt;Its cross platform capabilities allow me to work seamlessly from anywhere&lt;/li&gt;
&lt;li&gt;VSCode comes with built in Git integration which saves me loads of time&lt;/li&gt;
&lt;li&gt;VSCode’s interface feels natural and easy to navigate&lt;/li&gt;
&lt;li&gt;VSCode comes with built in debugging capabilities which helps me find errors quickly&lt;/li&gt;
&lt;li&gt;The code completion feature makes writing code easier and faster&lt;/li&gt;
&lt;li&gt;The extension marketplace provides access to thousands of extensions that can help with anything from syntax highlighting to project management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are so many benefits to using VSCode as my main IDE — I could go on forever! If you’re looking for an IDE that is fast, reliable and easy to use, VSCode is definitely a great option. Give it a try today!&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>vscode</category>
    </item>
    <item>
      <title>8 Reasons to consider TypeScript for your next web development project</title>
      <dc:creator>Stéphane Sulikowski</dc:creator>
      <pubDate>Mon, 24 Jan 2022 09:32:53 +0000</pubDate>
      <link>https://dev.to/sulistef/8-reasons-to-consider-typescript-for-your-next-web-development-project-2c2l</link>
      <guid>https://dev.to/sulistef/8-reasons-to-consider-typescript-for-your-next-web-development-project-2c2l</guid>
      <description>&lt;p&gt;If you’re looking for a more structured and sophisticated web development project language, TypeScript might be the right choice for you. Here are 8 reasons why you should consider using it for your next project:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. It can make code much more readable and organized.&lt;/strong&gt;&lt;br&gt;
TypeScript can help to clarify your code and make it more readable. It also helps to enforce a certain level of organization, which is especially helpful if you’re working on a large project with multiple developers.&lt;br&gt;
This makes the code easier to read and understand and can also help avoid potential coding conflicts down the road.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. It has strong typing, which helps to avoid errors.&lt;/strong&gt;&lt;br&gt;
TypeScript has strong typing, which can help to catch errors in your code before it’s ever compiled. This not only saves you time and hassle, but it can also help to avoid potential runtime errors.&lt;br&gt;
Strong typing is critical when working with large projects or teams, as it can help ensure that everyone is on the same page and that there are no surprises when it comes to the codebase.&lt;br&gt;
TypeScript also offers optional typing, which gives you more flexibility while still helping to catch errors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. It offers object-oriented programming features.&lt;/strong&gt;&lt;br&gt;
TypeScript offers object-oriented programming features, which can help to make your code more organized and efficient. This is especially helpful if you’re working on a complex project with multiple objects and classes.&lt;br&gt;
Object-oriented programming can also help to make your code more reusable and easier to maintain over time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Its typing files help keep everyone on the same page.&lt;/strong&gt;&lt;br&gt;
TypeScript typings files are a great way to keep everyone on the same page regarding coding standards. These typing files can be used to define all of the typings for a project, making it easier for other developers to understand and work with your code.&lt;br&gt;
This is especially helpful if you’re working with a large team or sharing your code with others. The typings files can also be used to generate type definitions for third-party libraries, making it easier to use those libraries in your project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. You can use it with JavaScript frameworks like React, AngularJS or Svelte.&lt;/strong&gt;&lt;br&gt;
TypeScript can be used with popular JavaScript frameworks like React, AngularJS and Svelte. This makes it an excellent choice for development projects that use these frameworks, as you can take advantage of the typings files and all of the other benefits that TypeScript offers.&lt;br&gt;
TypeScript also offers support for ES2015, which means that you can use the latest features of JavaScript with these frameworks.&lt;br&gt;
TypeScript is also being used more and more in mobile development, thanks to its support for React Native.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. It offers excellent compilation error messages.&lt;/strong&gt;&lt;br&gt;
TypeScript offers great compilation error messages, which can help you to find and fix any errors in your code quickly. This is especially helpful when you’re first starting to use TypeScript or if you’re working with a large codebase.&lt;br&gt;
Great compilation error messages are essential for any development tool, and TypeScript delivers in this area.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. You can use it to create reusable components.&lt;/strong&gt;&lt;br&gt;
TypeScript can be used to create reusable components, which is a great way to improve the organization and efficiency of your code. This is especially helpful if you’re working on a complex project with multiple objects and classes.&lt;br&gt;
Reusable components can also help to make your code more maintainable over time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. It’s constantly being improved by the TypeScript team.&lt;/strong&gt;&lt;br&gt;
TypeScript is constantly being improved by the TypeScript team, which means that you can always rely on it to be up-to-date and compliant with the latest standards. This is an excellent benefit for any development tool, as you can always count on it to work correctly and without any surprises.&lt;br&gt;
The TypeScript team is also constantly working to improve the usability and features of TypeScript. So far, they’ve done a great job in this area, and TypeScript is only getting better with time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hopefully, this gives you a good overview of why TypeScript might be a good choice for your next development project! If you’re interested in learning more, I encourage you to check out the official TypeScript website. Thanks for reading and …&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to setup a Svelte with Typescript project</title>
      <dc:creator>Stéphane Sulikowski</dc:creator>
      <pubDate>Thu, 20 Jan 2022 08:07:00 +0000</pubDate>
      <link>https://dev.to/sulistef/how-to-setup-a-svelte-with-typescript-project-2p9k</link>
      <guid>https://dev.to/sulistef/how-to-setup-a-svelte-with-typescript-project-2p9k</guid>
      <description>&lt;p&gt;TypeScript is a superset of JavaScript that provides optional static typing, classes, and modules. Static types allow TypeScript to provide more accurate type checking and tooling support. Classes and modules enable better organization of your code.&lt;/p&gt;

&lt;p&gt;TypeScript can be used with any existing JavaScript codebase. It transpiles down to plain old JavaScript so there’s no need to change your existing codebases.&lt;/p&gt;

&lt;p&gt;In this post, we’ll walk through how to set up a Svelte project with Typescript. We’ll start by creating a new project, then, we’ll add Typescript support and configure our project to use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Svelte and TypeScript
&lt;/h2&gt;

&lt;p&gt;Svelte is a new compiler that takes your JavaScript and turns it into efficient, production-ready code. Because Svelte watches the types of your variables and inserts the appropriate checks and optimizations, you don’t have to worry about performance problems or browser compatibility issues.&lt;br&gt;
TypeScript can be used with Svelte to provide type checking and tooling support. This can help you catch errors early in the development process, and ensure that your code is as efficient as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a New Project
&lt;/h2&gt;

&lt;p&gt;The first thing we need to do is create a new Svelte project. We can do this using the degit command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx degit sveltejs/template testApp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will install all the svelte project template.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up TypeScript
&lt;/h2&gt;

&lt;p&gt;Let’s get started by changing the src/app.svelte file with a code editor in our project.&lt;br&gt;
We will set the use of TypeScript language by changing&lt;br&gt;
&lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;&lt;br&gt;
in&lt;br&gt;
&lt;code&gt;&amp;lt;script lang="ts"&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we will run the setupTypeScript.js file to start using TypeScript in our application by typing in the terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node scripts/setupTypeScript.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Reinstall all dependencies with the terminal command:&lt;br&gt;
&lt;code&gt;npm install&lt;/code&gt;&lt;br&gt;
And we are ready to go!&lt;/p&gt;

&lt;h2&gt;
  
  
  Start the server
&lt;/h2&gt;

&lt;p&gt;We will use the terminal command&lt;br&gt;
&lt;code&gt;npm run dev&lt;/code&gt;&lt;br&gt;
and the server will be accessible from our browser at the specified url.&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%2F7t32wz1jjydyeip60r3r.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%2F7t32wz1jjydyeip60r3r.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Svelte and typescript are a powerful combination for developing web applications. Svelte provides a way to create efficient, production-ready code, while typescript provides type checking and tooling support. Together, they allow you to catch errors early in the development process, and ensure that your code is as efficient as possible.&lt;br&gt;
I hope you found this post helpful! If you have any questions or feedback, please feel free to leave a comment below. Thanks!&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How to set up a Node.js backend using Express.js and TypeScript</title>
      <dc:creator>Stéphane Sulikowski</dc:creator>
      <pubDate>Tue, 18 Jan 2022 09:57:35 +0000</pubDate>
      <link>https://dev.to/sulistef/how-to-set-up-a-nodejs-backend-using-expressjs-and-typescript-1655</link>
      <guid>https://dev.to/sulistef/how-to-set-up-a-nodejs-backend-using-expressjs-and-typescript-1655</guid>
      <description>&lt;p&gt;Node.js is one of the most popular node frameworks for web developers today, and when combined with Express.js, it can be even more powerful.&lt;/p&gt;

&lt;p&gt;Express is a node framework that lets you build node apps in an easy way by using node’s built-in middleware concept. This has many benefits like making your code more readable and maintainable, abstracting away boilerplate patterns like route handlers to make them reusable, etc.&lt;/p&gt;

&lt;p&gt;TypeScript is a superset of JavaScript that compiles to clean JavaScript output without any runtime errors or performance issues! It has many great features like static typing, modules, interfaces, and more.&lt;/p&gt;

&lt;p&gt;In this blog post, we’ll see how to set up a node.js backend using Express.js and TypeScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;If Node.js is not installed on your computer, download the proper installation package on [&lt;a href="https://nodejs.org"&gt;https://nodejs.org&lt;/a&gt;] and proceed to the installation.&lt;/p&gt;

&lt;p&gt;Then, we need to install the Express.js and TypeScript dependencies. For this, we can use npm: &lt;br&gt;
npm install express typescript --save-dev&lt;br&gt;
The —dev option will write the dependency as used for the development only. It will not be installed in a production environment.&lt;/p&gt;

&lt;p&gt;Create a new directory to store your project, and navigate inside with your terminal and initialise the project with :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init -y&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Install types
&lt;/h3&gt;

&lt;p&gt;It’s recommended to install the types so TypeScript can use type declarations :&lt;br&gt;
&lt;code&gt;npm install @types/node @types/express --save-dev&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Setup TypeScript with tsconfig.json
&lt;/h3&gt;

&lt;p&gt;Create a file named tsconfig.json that is the configuration file for TypeScript, and write the following options :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "compilerOptions": {
        "module": "commonjs",
        "esModuleInterop": true,
        "target": "es6",
        "noImplicitAny": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "outDir": "dist",
        "baseUrl": ".",
        "paths": {
            "*": [
                "node_modules/*"
            ]
        }
    },
    "include": [
        "src/**/*"
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that all the code has to be placed in a folder named « src » to be processed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add scripts to the package.json file
&lt;/h3&gt;

&lt;p&gt;We will add the following scripts to the package.json file to process and compile the Typescript code at start :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "scripts": {
    "prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
    "build": "tsc",
    "prestart": "npm run build",
    "start": "node ."
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add the main entry in the package.json file
&lt;/h3&gt;

&lt;p&gt;We will now tell node that the main entry point for our app is located in the dist/index.js file:&lt;br&gt;
&lt;code&gt;"main": "dist/index.js",&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Add a linter
&lt;/h3&gt;

&lt;p&gt;We will add now a linter to ensure code quality. It’s super handy because the linter check things beyond code syntax.&lt;br&gt;
Again let’s use a command in the terminal :&lt;br&gt;
npm install --save-dev tslint&lt;/p&gt;

&lt;p&gt;We will also create a configuration file and write the following options :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "defaultSeverity": "error",
    "extends": [
        "tslint:recommended"
    ],
    "jsRules": {},
    "rules": {
        "trailing-comma": [ false ],
        "no-console": [true, "warning"]
    },
    "rulesDirectory": []
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that we have an option that prevents usage of the console, but with a warning only and will not block the output if we decide to use it anyway.&lt;/p&gt;

&lt;p&gt;… and configuration is done !&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a server
&lt;/h2&gt;

&lt;p&gt;Now we can create an express app using node's App module.&lt;br&gt;
As we use TypeScript, please be aware that the includes are written in a different way :&lt;/p&gt;

&lt;p&gt;Insead of&lt;br&gt;
&lt;code&gt;const express = require('express');&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We will write&lt;br&gt;
&lt;code&gt;import express from 'express';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As we declared in the configuration, the main file is index.ts that is located in the « src » directory.&lt;br&gt;
We create the directory and file if needed and we write 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 express from 'express';

const app = express();

// declare a route with a response
app.get('/', (req, res) =&amp;gt; {
  res.send("What's up doc ?!");
});

// start the server
app.listen(8081, () =&amp;gt; {
  console.log(`server running : http://localhost:8081`);
});

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

&lt;/div&gt;



&lt;p&gt;Now time to run the server, in the root directory of the project we will write:&lt;br&gt;
npm run start&lt;br&gt;
The code will be compiled, and when the process is finishes we should see «server running : &lt;a href="http://localhost:8081%C2%A0%C2%BB"&gt;http://localhost:8081 »&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now we can type &lt;a href="http://localhost:8081"&gt;http://localhost:8081&lt;/a&gt; in our browser, and … 🥳&lt;/p&gt;
&lt;h2&gt;
  
  
  One more thing
&lt;/h2&gt;

&lt;p&gt;As you could see we wrote the server host and port in the code.&lt;br&gt;
To get more code friendly, we should write these infos as environment variables.&lt;br&gt;
To do so let’s add a npm package named &lt;em&gt;dotenv&lt;/em&gt;:&lt;br&gt;
&lt;code&gt;npm install dotenv --save&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We will create a file at the root of our project named &lt;code&gt;.env&lt;/code&gt;&lt;br&gt;
In this file let’s add the following information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BACK_HOST=localhost
BACK_PORT=8081
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in our index.ts file, let’s call these variables and use them for our server:&lt;br&gt;
&lt;/p&gt;

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

const app = express();
dotenv.config(); 


// declare a route with a response
app.get('/', (req, res) =&amp;gt; {
  res.send("What's up doc ?!");
});

// start the server
app.listen(process.env.BACK_PORT, () =&amp;gt; {
  console.log(`server running : http://${process.env.BACK_HOST}:${process.env.BACK_PORT}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that to access an env variable, follow the syntax:&lt;br&gt;
&lt;code&gt;process.env.NAME_OF_YOUR_VARIABLE_DECLARED_IN_THE_ENV_FILE&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this post, we've seen how to set up a node.js backend using Express.js and TypeScript. We've also seen some of the benefits that come with using these technologies together. &lt;br&gt;
I hope you found this useful!&lt;/p&gt;

&lt;p&gt;Happy coding !&lt;/p&gt;

</description>
      <category>node</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How to improve the use of the console in javascript</title>
      <dc:creator>Stéphane Sulikowski</dc:creator>
      <pubDate>Thu, 09 Dec 2021 17:51:52 +0000</pubDate>
      <link>https://dev.to/sulistef/how-to-improve-the-use-of-the-console-in-javascript-44ha</link>
      <guid>https://dev.to/sulistef/how-to-improve-the-use-of-the-console-in-javascript-44ha</guid>
      <description>&lt;p&gt;When we develop, and not only in javascript, it is regularly necessary to read the information contained in a variable or the execution result.&lt;/p&gt;

&lt;p&gt;In javascript, we have the Console object, which allows us to ask the program to write a message or a result during its execution.&lt;/p&gt;

&lt;p&gt;The most commonly used method, and one that I have used countless times, is the console.log() function, but there are other functions at our disposal that allow us to simplify the reading depending on the case.&lt;/p&gt;

&lt;h2&gt;
  
  
  first thing first : console.log()
&lt;/h2&gt;

&lt;p&gt;As mentioned above, this function is widely used and is usually one of the first functions learned in javascript.&lt;br&gt;
You have to pass the message or the variable in the function to see the result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Hello");
// Will display : Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is possible to concatenate a message and the content of a variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myVariable = "world";
console.log("Hello " + myVariable);
// Will display : Hello world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or to write a title and display the content of a variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myVariable = "Hello";
console.log("My message :", myVariable);
// Will display : My message : Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  great tables : console.table()
&lt;/h2&gt;

&lt;p&gt;This efficient function will display the information contained in an array variable by formatting the result.&lt;br&gt;
Let's use an example to illustrate how it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myTable = [1, 2, 3, 4, 5]
console.table(myTable);
// Will display :
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
│    0    │   1    │
│    1    │   2    │
│    2    │   3    │
│    3    │   4    │
└─────────┴────────┘

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

&lt;/div&gt;



&lt;p&gt;A neat and readable table is displayed, much more practical than :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(myTable);
// Will display : [1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the magic happens if we display the content of an array of objects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myTable = [
    {
        nom: "name 1",
        prenom: "firstname 1",
        age: 20 
    },
    {
        nom: "name 2",
        prenom: "firstname 2",
        age: 30 
    },
    {
        nom: "name 3",
        prenom: "firstname 3",
        age: 40 
    },
];
console.table(myTable);

// Will display :
┌─────────┬──────────┬────────────────────┬─────┐
│ (index) │   name   │     firstname      │ age │
├─────────┼──────────┼────────────────────┼─────┤
│    0    │ 'name 1' │   'firstname 1'    │ 20  │
│    1    │ 'name 2' │   'firstname 2'    │ 30  │
│    2    │ 'name 3' │   'firstname 3'    │ 40  │
└─────────┴──────────┴────────────────────┴─────┘

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

&lt;/div&gt;



&lt;p&gt;Unfortunately, if you use values containing objects, the table will no longer be structured accordingly but display the data more rawly.&lt;br&gt;
But this first level is already convenient!&lt;/p&gt;
&lt;h2&gt;
  
  
  grouping infos : console.group()
&lt;/h2&gt;

&lt;p&gt;When it comes to organizing info displayed in the console, console.group() allow indenting output messages.&lt;br&gt;
It’s, of course, possible to have multiple indentation levels by nesting a group into a group.&lt;/p&gt;

&lt;p&gt;Again let’s take an example to show how it works :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myArray = [1, 2, 3];

console.group();
    console.log(myArray[0]);
    console.group();
        console.log(myArray[1]);
        console.group();
            console.log(myArray[2]);
        console.groupEnd();
    console.groupEnd();
console.groupEnd();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code displays :&lt;/p&gt;

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

&lt;p&gt;This indentation allows you to get more readable outputs for debugging or any other needs.&lt;/p&gt;

&lt;p&gt;Please note that you have to close the group with console.groupEnd();&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The console objets offers several methods to optimize the outputs you need. You can check all the other possibilities : [&lt;a href="https://developer.mozilla.org/en/docs/Web/API/Console"&gt;https://developer.mozilla.org/en/docs/Web/API/Console&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Happy coding !&lt;/p&gt;

&lt;p&gt;Article also available on &lt;a href="https://medium.com/@sulistef/how-to-better-use-the-console-in-javascript-f27492fdbcec"&gt;Medium&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>console</category>
    </item>
    <item>
      <title>How to create a custom React hook to fetch an API (using TypeScript)?</title>
      <dc:creator>Stéphane Sulikowski</dc:creator>
      <pubDate>Thu, 09 Dec 2021 17:45:58 +0000</pubDate>
      <link>https://dev.to/sulistef/how-to-create-a-custom-react-hook-to-fetch-an-api-using-typescript-ioi</link>
      <guid>https://dev.to/sulistef/how-to-create-a-custom-react-hook-to-fetch-an-api-using-typescript-ioi</guid>
      <description>&lt;h1&gt;
  
  
  How to create a custom React hook to fetch an API (using TypeScript)?
&lt;/h1&gt;

&lt;p&gt;Hooks are convenient for modern react development. The react framework comes with standard hooks to manage state, for example, with useState, and here we will write our hook to fetch data from any API.&lt;/p&gt;

&lt;p&gt;Buț first …&lt;/p&gt;

&lt;h2&gt;
  
  
  … what is a hook?
&lt;/h2&gt;

&lt;p&gt;A hook is a javascript or typescript function that can include other hooks. Its name starts with « use », and this function can only be called inside a React functional component. &lt;/p&gt;

&lt;p&gt;You can find the &lt;a href="https://en.reactjs.org/docs/hooks-rules.html" rel="noopener noreferrer"&gt;complete Rules of Hooks documentation here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s start
&lt;/h2&gt;

&lt;p&gt;First, create a new React project using Typescript.&lt;br&gt;
In the terminal, navigate to the desired folder, and with the terminal command :&lt;br&gt;
&lt;code&gt;npx create-react-app apihook --template typescript&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The project is ready, time to think about the output of our hook to set the goal.&lt;/p&gt;

&lt;h2&gt;
  
  
  The output
&lt;/h2&gt;

&lt;p&gt;Our hook will fetch an API, and the function will return a result.&lt;br&gt;
For this example, we want to get the following information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;response status code: to test the response code&lt;/li&gt;
&lt;li&gt;response status text: to get the response status in a more readable way&lt;/li&gt;
&lt;li&gt;data: data provided by the API&lt;/li&gt;
&lt;li&gt;error: description of the error if one occurs&lt;/li&gt;
&lt;li&gt;loading: to know if the process is running&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will write a type to set that!&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding!
&lt;/h2&gt;

&lt;p&gt;I will create a new folder to store my hook and a new file named useApiHook.ts&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%2Fiv3c8g8nw7smudk86mxm.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%2Fiv3c8g8nw7smudk86mxm.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And set my type as following :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

export type TApiResponse = {
  status: Number;
  statusText: String;
  data: any;
  error: any;
  loading: Boolean;
};


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

&lt;/div&gt;

&lt;p&gt;We will now declare my hook as a function that will take a string containing the url as parameter and return a TApiResponse :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

export type TApiResponse = {
  status: Number;
  statusText: String;
  data: any;
  error: any;
  loading: Boolean;
};

export const useApiGet = (url: string): TApiResponse =&amp;gt; {};


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

&lt;/div&gt;

&lt;p&gt;We will also use the state to store the information before returning the response. For this purpose, we will use a standard hook named useState, and import this function from the React framework :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import { useState } from 'react';

export type TApiResponse = {
  status: Number;
  statusText: String;
  data: any;
  error: any;
  loading: Boolean;
};

export const useApiGet = (url: string): TApiResponse =&amp;gt; {
  const [status, setStatus] = useState&amp;lt;Number&amp;gt;(0);
  const [statusText, setStatusText] = useState&amp;lt;String&amp;gt;('');
  const [data, setData] = useState&amp;lt;any&amp;gt;();
  const [error, setError] = useState&amp;lt;any&amp;gt;();
  const [loading, setLoading] = useState&amp;lt;boolean&amp;gt;(false);
};


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

&lt;/div&gt;

&lt;p&gt;Please note that we initialize status and textStatus to avoid « undefined ». If not, we would get a TypeScript error telling that it doesn’t match the type we defined (the power of TypeScript !).&lt;/p&gt;

&lt;p&gt;Time to get the data!&lt;br&gt;
Here we will use an async function to create a promise and get the data. We will also use try/catch to catch an error if something wrong happens.&lt;br&gt;
We also set isLoading to ‘true’, so the process will be set as running :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import { useState } from 'react';

export type TApiResponse = {
  status: Number;
  statusText: String;
  data: any;
  error: any;
  loading: Boolean;
};

export const useApiGet = (url: string): TApiResponse =&amp;gt; {
  const [status, setStatus] = useState&amp;lt;Number&amp;gt;(0);
  const [statusText, setStatusText] = useState&amp;lt;String&amp;gt;('');
  const [data, setData] = useState&amp;lt;any&amp;gt;();
  const [error, setError] = useState&amp;lt;any&amp;gt;();
  const [loading, setLoading] = useState&amp;lt;boolean&amp;gt;(false);

  const getAPIData = async () =&amp;gt; {
    setLoading(true);
    try {
      const apiResponse = await fetch(url);
      const json = await apiResponse.json();
    } catch (error) {
    }
  };
};


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

&lt;/div&gt;

&lt;p&gt;We are almost done !&lt;br&gt;
Now let’s store the results in the different states, and at the end, set isLoading to false to declare that the process is finished:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import { useState } from 'react';

export type TApiResponse = {
  status: Number;
  statusText: String;
  data: any;
  error: any;
  loading: Boolean;
};

export const useApiGet = (url: string): TApiResponse =&amp;gt; {
  const [status, setStatus] = useState&amp;lt;Number&amp;gt;(0);
  const [statusText, setStatusText] = useState&amp;lt;String&amp;gt;('');
  const [data, setData] = useState&amp;lt;any&amp;gt;();
  const [error, setError] = useState&amp;lt;any&amp;gt;();
  const [loading, setLoading] = useState&amp;lt;boolean&amp;gt;(false);

  const getAPIData = async () =&amp;gt; {
    setLoading(true);
    try {
      const apiResponse = await fetch(url);
      const json = await apiResponse.json();
      setStatus(apiResponse.status);
      setStatusText(apiResponse.statusText);
      setData(json);
    } catch (error) {
      setError(error);
    }
    setLoading(false);
  };
};


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

&lt;/div&gt;

&lt;p&gt;To finish our custom hook, we need to trigger the function we have crated. To do so, we use another standard hook : useEffect().&lt;br&gt;
This hook will execute code when the component loads or some variable has changed.&lt;br&gt;
We will only use it when the component is loaded for our purpose.&lt;br&gt;
We need first to import it and use it to call our function :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import { useState, useEffect } from 'react';

export type TApiResponse = {
  status: Number;
  statusText: String;
  data: any;
  error: any;
  loading: Boolean;
};

export const useApiGet = (url: string): TApiResponse =&amp;gt; {
  const [status, setStatus] = useState&amp;lt;Number&amp;gt;(0);
  const [statusText, setStatusText] = useState&amp;lt;String&amp;gt;('');
  const [data, setData] = useState&amp;lt;any&amp;gt;();
  const [error, setError] = useState&amp;lt;any&amp;gt;();
  const [loading, setLoading] = useState&amp;lt;boolean&amp;gt;(false);

  const getAPIData = async () =&amp;gt; {
    setLoading(true);
    try {
      const apiResponse = await fetch(url);
      const json = await apiResponse.json();
      setStatus(apiResponse.status);
      setStatusText(apiResponse.statusText);
      setData(json);
    } catch (error) {
      setError(error);
    }
    setLoading(false);
  };

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

  return { status, statusText, data, error, loading };
};


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

&lt;/div&gt;

&lt;p&gt;Now that our hook is done let’s call it in the main application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use the custom hook
&lt;/h2&gt;

&lt;p&gt;In our example, we will call the hook to fetch a movie database API and console.log the result. &lt;br&gt;
We need to create an account on omdbapi.com to get a free API key required to pull the data. &lt;/p&gt;

&lt;p&gt;In the file App.tsx, we will :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;import the type and the custom hook&lt;/li&gt;
&lt;li&gt;add the call to the API and store the result in a variable called &lt;code&gt;data&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then to display the result, I will use the property &lt;code&gt;loading&lt;/code&gt;from the response to avoid multiple print during the process:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&lt;p&gt;import React from 'react';&lt;br&gt;
import logo from './logo.svg';&lt;br&gt;
import './App.css';&lt;br&gt;
import { useApiGet, TApiResponse } from './hooks/useApiHook';&lt;/p&gt;

&lt;p&gt;function App() {&lt;/p&gt;

&lt;p&gt;// call to the hook&lt;br&gt;
  const data: TApiResponse = useApiGet(&lt;br&gt;
    '&lt;a href="http://www.omdbapi.com/?s=Guardians&amp;amp;apikey=xxxxxxxx" rel="noopener noreferrer"&gt;http://www.omdbapi.com/?s=Guardians&amp;amp;amp;apikey=xxxxxxxx&lt;/a&gt;'&lt;br&gt;
  );&lt;/p&gt;

&lt;p&gt;// print the output&lt;br&gt;
  if (!data.loading) console.log(data);&lt;/p&gt;

&lt;p&gt;return (&lt;br&gt;
    &amp;lt;div className="App"&amp;gt;&lt;br&gt;
      &amp;lt;header className="App-header"&amp;gt;&lt;br&gt;
        &amp;lt;img src={logo} className="App-logo" alt="logo" /&amp;gt;&lt;br&gt;
        &amp;lt;p&amp;gt;&lt;br&gt;
          Edit &amp;lt;code&amp;gt;src/App.tsx&amp;lt;/code&amp;gt; and save to reload.&lt;br&gt;
        &amp;lt;/p&amp;gt;&lt;br&gt;
        &amp;lt;a&lt;br&gt;
          className="App-link"&lt;br&gt;
          href="&lt;a href="https://reactjs.org" rel="noopener noreferrer"&gt;https://reactjs.org&lt;/a&gt;"&lt;br&gt;
          target="_blank"&lt;br&gt;
          rel="noopener noreferrer"&amp;gt;&lt;br&gt;
          Learn React&lt;br&gt;
        &amp;lt;/a&amp;gt;&lt;br&gt;
      &amp;lt;/header&amp;gt;&lt;br&gt;
    &amp;lt;/div&amp;gt;&lt;br&gt;
  );&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;export default App;&lt;/p&gt;

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

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Run the app&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Finally let’s run the app by typing in the console :&lt;br&gt;
&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And …&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%2Fz8o26s0aioplmaxoac8o.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%2Fz8o26s0aioplmaxoac8o.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🥳&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hooks can be super handy and allow the creation of reusable functions. They have to follow some rules to build them and are very flexible.&lt;br&gt;
For our example, we could go further and extend the function to handle parameters, other methods, some checks and controls, but I wanted to keep it simple to explain the principle.&lt;/p&gt;

&lt;p&gt;Now I invite you to create custom hooks for your react apps, and feel free to share some usages in the comments.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;Article also available on &lt;a href="https://medium.com/@sulistef/how-to-create-a-custom-react-hook-to-fetch-an-api-using-typescript-dcb68b49b9bd" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
      <category>hook</category>
    </item>
  </channel>
</rss>
