<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tomescu Dani on Medium]]></title>
        <description><![CDATA[Stories by Tomescu Dani on Medium]]></description>
        <link>https://medium.com/@tomescudani?source=rss-75a079a5c060------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Pm2KldW_Z_yIr_oeKxnRng.jpeg</url>
            <title>Stories by Tomescu Dani on Medium</title>
            <link>https://medium.com/@tomescudani?source=rss-75a079a5c060------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 05:35:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tomescudani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[React.js Boilerplate (Context, Routing included)]]></title>
            <link>https://medium.com/@tomescudani/react-js-boilerplate-context-routing-included-24f71524262e?source=rss-75a079a5c060------2</link>
            <guid isPermaLink="false">https://medium.com/p/24f71524262e</guid>
            <dc:creator><![CDATA[Tomescu Dani]]></dc:creator>
            <pubDate>Tue, 10 Sep 2024 14:06:03 GMT</pubDate>
            <atom:updated>2024-09-10T14:06:03.635Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello test</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24f71524262e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Essential Tips For Beginner Web Developers]]></title>
            <link>https://medium.com/@tomescudani/5-essential-tips-for-beginner-web-developers-919e5523fa92?source=rss-75a079a5c060------2</link>
            <guid isPermaLink="false">https://medium.com/p/919e5523fa92</guid>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Tomescu Dani]]></dc:creator>
            <pubDate>Fri, 28 Jul 2023 16:31:01 GMT</pubDate>
            <atom:updated>2023-07-28T16:31:01.294Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Q5YTvZWCF2FHSJnREbW9oQ.png" /></figure><p>As a Full Stack Engineer with 5 years experience in the software development industry, I’ve had the opportunity to learn valuable lessons along the way.</p><p>Starting the journey to become a software developer can be both exciting and overwhelming. This article will offer you a few helpful tips regarding your career.</p><p>Let’s begin !</p><ol><li><strong>Focus on Fundamentals</strong></li></ol><p>At the beginning there are many things you are not familiar with, from slugs to a programming language. It’s important to get a brief overview on which part of programming would you like to focus.</p><p>There are a lot of great areas such as Web Development, Mobile Development, Machine Learning, Automotive etc.</p><p>Let’s speak about web development. There are two “main” parts: Frontend and Backend.</p><p>Frontend is mainly what a user sees and interacts with and backend is all the magic in the backyard.</p><p>You can either go with Frontend Development, Backend Development or both. It’s best at the beginning to start with one of them.</p><p>You can start with a brief overview on how web development works. There are a lot of youtube videos on that.</p><p>The next thing will be understanding concepts in:</p><ul><li>HTML, CSS, JavaScript if you are going with the Frontend (although I recommend getting a basic overview even if you choose Backend with other language than Node.js)</li><li>A backend language like Node.js, Java, C#, Python etc</li></ul><p>Once you are familiar with basic concepts such as language-specific keywords, data structures and simple algorithms, it’s time to dive deeper into practice.</p><p>2. <strong>Practice, a lot</strong></p><p>Learning by doing remains one of the best ways to learn something new. Works the same with programming. Once you feel at least a little bit familiar with basic functionalities (such as declaring variables, creating simple functions, iterations) try building a small project.</p><p>Building something can be exciting and challenging — often more challenging than it seems at first glance. It’s a great way of combining practice with theory, because every time you hit a wall, you need to google it and find out what goes wrong.</p><p>3. <strong>Read other people’s code</strong></p><p>Reading other people’s code from articles, github projects, youtube videos is a great way to discover new ways of doing different kind of stuff, different approach to different problems and sometimes different great tools, techniques, tricks that you didn’t know about.</p><p>4. <strong>Ask for feedback</strong></p><p>After some boring theory at the beginning and some small projects you’ll most probably have no idea whether you are on the right path or not.</p><p>That is the perfect time to ask for feedback. Ask an experienced programmer to review your code, give you some guidance or even do some pair programming.</p><p>There are a lot of things you will be doing wrong without even knowing and an experienced developer can easily guide you through basic mistakes, solidifying your fundamentals.</p><p>5. <strong>Cultivate soft skills</strong></p><p>Software development is not just about writing code. It’s also about effective communication and teamwork. You will very rarely work only by yourself on a real project.</p><p>Being able to collaborate with your team plays a huge success in a developer’s career, especially at the beginning.</p><p><a href="https://medium.com/@tomescudani">Follow for more</a></p><p><a href="https://www.buymeacoffee.com/dantomescu">☕ Buy me a coffee</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=919e5523fa92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Tips & Tricks]]></title>
            <link>https://medium.com/@tomescudani/javascript-tips-tricks-7e9858af2a4?source=rss-75a079a5c060------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e9858af2a4</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tips]]></category>
            <dc:creator><![CDATA[Tomescu Dani]]></dc:creator>
            <pubDate>Fri, 28 Jul 2023 12:32:29 GMT</pubDate>
            <atom:updated>2023-07-28T12:32:29.212Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s see some useful JavaScript tips &amp; tricks</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*UPl0fH0cEfFDXVhxtPo0lA.jpeg" /></figure><ol><li><strong>Promises and Async/Await</strong></li></ol><blockquote>Promises and Async/Await are invaluable for handling asynchronous operations in a more readable and maintainable way. They avoid callback hell and provide better error handling.</blockquote><pre>const fetchData = () =&gt; {<br>  return new Promise((resolve, reject) =&gt; {<br>    // Asynchronous operation (e.g., fetching data from a server)<br>    setTimeout(() =&gt; {<br>      const data = { name: &#39;John&#39;, age: 30 };<br>      resolve(data); // Success<br>      // reject(new Error(&#39;Data not found&#39;)); // Error<br>    }, 1000);<br>  });<br>};<br><br>// Using Promises<br>fetchData()<br>  .then((data) =&gt; console.log(data))<br>  .catch((error) =&gt; console.error(error.message));<br><br>// Using Async/Await<br>const fetchAsync = async () =&gt; {<br>  try {<br>    const data = await fetchData();<br>    console.log(data);<br>  } catch (error) {<br>    console.error(error.message);<br>  }<br>};<br><br>fetchAsync();</pre><p>2. <strong>Object Destructuring with renaming</strong></p><blockquote>When using object destructuring, you can rename variables to make your code more expressive and avoid naming conflicts.</blockquote><pre>const person = { firstName: &#39;John&#39;, lastName: &#39;Doe&#39; };<br><br>// Renaming properties using object destructuring<br>const { firstName: fName, lastName: lName } = person;<br>console.log(fName, lName); // Output: John Doe</pre><p>3. <strong>reduce() Method</strong></p><blockquote>The reduce() method is incredibly powerful and can be used to perform various operations on arrays, such as calculating sums, products, or transforming data.</blockquote><pre>const numbers = [1, 2, 3, 4, 5];<br><br>// Calculating the sum of all elements using reduce<br>const sum = numbers.reduce((acc, num) =&gt; acc + num, 0);<br>console.log(sum); // Output: 15<br><br>// Transforming an array of objects into an object using reduce<br>const data = [<br>  { id: 1, name: &#39;John&#39; },<br>  { id: 2, name: &#39;Jane&#39; },<br>  { id: 3, name: &#39;Alice&#39; },<br>];<br><br>const dataObject = data.reduce((acc, item) =&gt; {<br>  acc[item.id] = item.name;<br>  return acc;<br>}, {});<br><br>console.log(dataObject);<br>// Output:<br>// {<br>//   1: &#39;John&#39;,<br>//   2: &#39;Jane&#39;,<br>//   3: &#39;Alice&#39;<br>// }</pre><p>4. <strong>Destructuring Nested Objects and Arrays</strong></p><blockquote>You can use destructuring not only for shallow objects and arrays but also for deeply nested ones.</blockquote><pre>const user = {<br>  name: &#39;John&#39;,<br>  age: 30,<br>  address: {<br>    city: &#39;New York&#39;,<br>    country: &#39;USA&#39;,<br>  },<br>  hobbies: [&#39;reading&#39;, &#39;coding&#39;],<br>};<br><br>const {<br>  name,<br>  age,<br>  address: { city, country },<br>  hobbies: [hobby1, hobby2],<br>} = user;<br><br>console.log(name, age, city, country, hobby1, hobby2);<br>// Output: John 30 New York USA reading coding</pre><p>5. <strong>Function Currying</strong></p><blockquote>Function currying is a technique that transforms a function that takes multiple arguments into a sequence of functions, each taking a single argument. It allows you to partially apply arguments and create more specialized functions.</blockquote><pre>function add(a) {<br>  return function (b) {<br>    return a + b;<br>  };<br>}<br><br>const add5 = add(5);<br>console.log(add5(3)); // Output: 8<br>console.log(add5(7)); // Output: 12</pre><p><a href="https://medium.com/@tomescudani">Follow for more</a></p><p><a href="https://www.buymeacoffee.com/dantomescu">☕ Buy me a coffee</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e9858af2a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 Common JavaScript Interview Questions for Beginners]]></title>
            <link>https://medium.com/@tomescudani/10-common-javascript-interview-questions-for-beginners-a48f7d0eb851?source=rss-75a079a5c060------2</link>
            <guid isPermaLink="false">https://medium.com/p/a48f7d0eb851</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tomescu Dani]]></dc:creator>
            <pubDate>Thu, 27 Jul 2023 17:02:01 GMT</pubDate>
            <atom:updated>2023-07-27T17:02:01.043Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript is a powerful and widely-used programming language that is mainly used for, but not limited to, web development.</p><p>As a beginner preparing for JavaScript interviews, it’s crucial to be familiar with fundamental concepts and be able to showcase your skills. In this article we’ll explore ten common interview questions for beginners with answers for each one of them</p><p><strong>Let’s begin !</strong></p><ol><li>What is JavaScript?</li></ol><blockquote>JavaScript is a lightweight, interpreted programming language that enables dynamic and interactive content on web pages. It runs directly in the browser and allows developers to manipulate HTML elements, handle events, and communicate with servers.</blockquote><p>2. How do you declare variables in JavaScript?</p><blockquote>In JavaScript, you can declare variables using var, let, or const. var has function-level scope, while let and const have block-level scope. Additionally, const variables cannot be reassigned after declaration.</blockquote><pre>// Using var (function-scoped)<br>function exampleVar() {<br>  if (true) {<br>    var x = 10;<br>  }<br>  console.log(x); // Output: 10<br>}<br><br>// Using let (block-scoped)<br>function exampleLet() {<br>  if (true) {<br>    let y = 5;<br>  }<br>  console.log(y); // Error: y is not defined<br>}<br><br>// Using const (block-scoped, cannot be reassigned)<br>const PI = 3.14;<br>PI = 3.14159; // Error: Assignment to constant variable</pre><p>3. What are the data types in JavaScript?</p><blockquote>JavaScript has six primitive data types: string, number, boolean, null, undefined, and symbol. Additionally, it has the complex data type object, which includes arrays, functions, and objects.</blockquote><pre>let name = &quot;John&quot;; // string<br>let age = 30; // number<br>let isStudent = true; // boolean<br><br>let person = null; // null<br>let city; // undefined<br><br>let hobbies = [&quot;reading&quot;, &quot;swimming&quot;, &quot;coding&quot;]; // array<br>let personObj = { name: &quot;Alice&quot;, age: 25 }; // object</pre><p>4. How do you check the type of a variable?</p><blockquote>You can use the typeof operator to determine the type of a variable.</blockquote><pre>let x = 5;<br>console.log(typeof x); // Output: &quot;number&quot;<br><br>let y = &quot;Hello&quot;;<br>console.log(typeof y); // Output: &quot;string&quot;<br><br>let z = true;<br>console.log(typeof z); // Output: &quot;boolean&quot;<br><br>let obj = { name: &quot;John&quot; };<br>console.log(typeof obj); // Output: &quot;object&quot;<br><br>let arr = [1, 2, 3];<br>console.log(typeof arr); // Output: &quot;object&quot;</pre><ul><li>Note that obj and arr return the same value ‘object’. If you want to specifically check whether arr is actually an array you must use “Array.isArray(arr)”</li></ul><p>5. Explain reference types in JavaScript</p><blockquote>In JavaScript, reference types are a category of data types that don’t store the actual data directly but instead hold a reference (memory address) to the location where the data is stored. When you assign a reference type to a variable, the variable contains a pointer to the memory location where the data is stored. This is different from primitive data types, which directly store the value itself.</blockquote><p>The reference types in JavaScript are objects and arrays.</p><ul><li>Object example:</li></ul><pre>// Creating an object<br>const person = {<br>  name: &quot;John&quot;,<br>  age: 30,<br>  city: &quot;New York&quot;,<br>};<br><br>// Creating a new variable and assigning the object to it<br>const anotherPerson = person;<br><br>// Modifying the object through the new variable<br>anotherPerson.age = 35;<br><br>// The change is reflected in the original object<br>console.log(person.age); // Output: 35</pre><ul><li>Array example:</li></ul><pre>// Creating an array<br>const fruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;orange&quot;];<br><br>// Creating a new variable and assigning the array to it<br>const otherFruits = fruits;<br><br>// Modifying the array through the new variable<br>otherFruits.push(&quot;grape&quot;);<br><br>// The change is reflected in the original array<br>console.log(fruits); // Output: [&quot;apple&quot;, &quot;banana&quot;, &quot;orange&quot;, &quot;grape&quot;]</pre><p>6. What is hoisting in JavaScript?</p><blockquote>Hoisting is a JavaScript behavior where variable and function declarations are moved to the top of their scope during the compilation phase. However, only declarations are hoisted, not initializations.</blockquote><pre>console.log(x); // Output: undefined<br>var x = 5;<br><br>// The above code is equivalent to:<br>// var x;<br>// console.log(x);<br>// x = 5;</pre><ul><li>Note that only variables declared with ‘var’ keyword are hoisted. If you use let or const it will return an error</li></ul><p>7. How do you handle errors in JavaScript?</p><blockquote>The try-catch-finally statement allows you to handle errors gracefully. Code within the try block is executed, and if an error occurs, the catch block is triggered, allowing you to handle the error. The finally block executes regardless of whether an error occurred or not.</blockquote><pre>try {<br>  // Code that may throw an error<br>  let result = 10 / 0;<br>} catch (error) {<br>  console.log(&quot;Error:&quot;, error); // Output: &quot;Error: Infinity&quot;<br>} finally {<br>  console.log(&quot;Execution completed.&quot;);<br>}<br><br>// Output:<br>// &quot;Error: Infinity&quot;<br>// &quot;Execution completed.&quot;</pre><p>8. What are closures in JavaScript?</p><p>A closure is a function that retains access to variables from its lexical scope even after the outer function has finished executing. Closures are crucial for maintaining data privacy and creating “private” variables.</p><pre>function outerFunction() {<br>  let counter = 0<br>  return function innerFunction() {<br>    counter++;<br>    console.log(counter)<br>  };<br>}<br><br>const innerFunc = outerFunction();<br>innerFunc(); // Output: 1<br>innerFunc(); // Output: 2</pre><p>9. How can you iterate over objects and arrays in JavaScript?</p><blockquote>There are several ways to iterate through object and arrays, such as ‘for…in’, ‘for…of’ loop, and array methods like ‘forEach’, ‘map’, ‘filter’, ‘reduce’</blockquote><ul><li>Using the classic ‘for’ loop:</li></ul><pre>const colors = [&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;];<br>for (let i = 0; i &lt; colors.length; i++) {<br>  console.log(colors[i]);<br>}</pre><ul><li>Using ‘for…of’ loop:</li></ul><pre>const colors = [&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;];<br>for (const color of colors) {<br>  console.log(color);<br>}</pre><ul><li>Using ‘for…in’ loop for objects:</li></ul><pre>const person = {<br>  name: &quot;John&quot;,<br>  age: 30,<br>  city: &quot;New York&quot;,<br>};<br><br>for (const key in person) {<br>  console.log(`key: ${key}, value: ${person[key]}`); // key: name, value: John<br>}</pre><ul><li>Using forEach (note that forEach does not return a new array):</li></ul><pre>const colors = [&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;];<br>colors.forEach((color) =&gt; {<br>  console.log(color);<br>});</pre><ul><li>Using map (returns a new array):</li></ul><pre>const numbers = [1, 2, 3];<br>const squares = numbers.map((num) =&gt; num * num);<br>console.log(squares); // Output: [1, 4, 9]</pre><ul><li>Using ‘filter’</li></ul><pre>const numbers = [1, 2, 3, 4, 5];<br>const evenNumbers = numbers.filter((num) =&gt; num % 2 === 0);<br>console.log(evenNumbers); // Output: [2, 4]</pre><ul><li>Using ‘reduce’:</li></ul><pre>const numbers = [1, 2, 3, 4, 5];<br>const sum = numbers.reduce((acc, num) =&gt; acc + num, 0);<br>console.log(sum); // Output: 15</pre><p>10. What is the difference between ‘==’ and ‘===’ in JavaScript?</p><blockquote>In JavaScript, == (loose equality) and === (strict equality) are comparison operators used to compare values. The double equal (==) only compares the value and the triple equal (===) compares the type AND the value</blockquote><pre>console.log(5 == &quot;5&quot;); // Output: true<br>console.log(5 === &quot;5&quot;); // Output: false<br>console.log(null == undefined); // Output: true<br>console.log(0 == false); // Output: true<br>console.log(0 === false); // Output: false</pre><p><a href="https://medium.com/@tomescudani">Follow for more</a></p><p><a href="https://www.buymeacoffee.com/dantomescu">☕ Buy me a coffee</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a48f7d0eb851" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using React Context as a Global State Management]]></title>
            <link>https://medium.com/@tomescudani/using-react-context-as-a-global-state-management-77ba9341d561?source=rss-75a079a5c060------2</link>
            <guid isPermaLink="false">https://medium.com/p/77ba9341d561</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Tomescu Dani]]></dc:creator>
            <pubDate>Thu, 27 Jul 2023 11:02:27 GMT</pubDate>
            <atom:updated>2023-07-27T11:02:27.086Z</atom:updated>
            <content:encoded><![CDATA[<p>React Context is the built-in method that react offers to handle the global state management, as an alternative to third party libraries such as Redux or Mobx.</p><p>State management is a critical aspect of modern web development, offering many benefits such as avoiding prop drilling</p><p>Let’s start by creating a global state, following the next steps:</p><ol><li>Create a new context using ‘React.createContext()’</li><li>Wrap your application with the Provider component to get access to the context</li></ol><pre>// StateContext.js<br>import React, { createContext, useReducer } from &quot;react&quot;;<br><br>// Initial state<br>const initialState = {<br>  count: 0,<br>};<br><br>// Reducer function<br>const reducer = (state, action) =&gt; {<br>  switch (action.type) {<br>    case &quot;INCREMENT&quot;:<br>      return { ...state, count: state.count + 1 };<br>    case &quot;DECREMENT&quot;:<br>      return { ...state, count: state.count - 1 };<br>    default:<br>      return state;<br>  }<br>};<br><br>// Create the context<br>const StateContext = createContext();<br><br>// Provider component<br>const StateProvider = ({ children }) =&gt; {<br>  const [state, dispatch] = useReducer(reducer, initialState);<br><br>  return (<br>    &lt;StateContext.Provider value={{ state, dispatch }}&gt;<br>      {children}<br>    &lt;/StateContext.Provider&gt;<br>  );<br>};<br><br>export { StateContext, StateProvider };</pre><p>Now let’s set the state provider:</p><pre>// App.js<br><br>import React from &quot;react&quot;;<br>import { StateProvider } from &quot;./StateContext&quot;;<br>import Counter from &quot;./Counter&quot;;<br><br>function App() {<br>  return (<br>    &lt;StateProvider&gt;<br>      &lt;Counter /&gt;<br>    &lt;/StateProvider&gt;<br>  );<br>}<br><br>export default App;</pre><p>Now we need a Counter component where we’ll use the global context</p><pre>// Counter.js<br>import React, { useContext } from &quot;react&quot;;<br>import { StateContext } from &quot;./StateContext&quot;;<br><br>const Counter = () =&gt; {<br>  const { state, dispatch } = useContext(StateContext);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h2&gt;Count: {state.count}&lt;/h2&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &quot;INCREMENT&quot; })}&gt;Increment&lt;/button&gt;<br>      &lt;button onClick={() =&gt; dispatch({ type: &quot;DECREMENT&quot; })}&gt;Decrement&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default Counter;</pre><p>Now we have a global state management that has a count variable and two dispatch types to increment/decrement the values</p><p><a href="https://medium.com/@tomescudani">Follow for more</a></p><p><a href="https://www.buymeacoffee.com/dantomescu">☕ Buy me a coffee</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77ba9341d561" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating RESTful APIs with Docker, Node.js, Express, and PostgreSQL]]></title>
            <link>https://medium.com/@tomescudani/creating-restful-apis-with-docker-node-js-express-and-postgresql-75a32a47a1e9?source=rss-75a079a5c060------2</link>
            <guid isPermaLink="false">https://medium.com/p/75a32a47a1e9</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tomescu Dani]]></dc:creator>
            <pubDate>Wed, 26 Jul 2023 15:59:39 GMT</pubDate>
            <atom:updated>2023-07-26T17:59:01.016Z</atom:updated>
            <content:encoded><![CDATA[<p>Building RESTful APIs is a crucial skill for creating scalable and efficient applications.</p><p>In this article we will develop a RESTful API using the following technologies:</p><ul><li>Node.js</li><li>Docker</li><li>Express.js</li><li>PostgreSQL</li><li>Sequelize as ORM</li><li>TypeScript</li></ul><p>Let’s get started !</p><ol><li>Setup the project:</li></ol><blockquote>First, let’s create a directory and install the necessary dependencies. Make sure you have docker and node.js already installed</blockquote><pre># Create a new directory and navigate to it<br>mkdir restful-api-express-sequelize<br>cd restful-api-express-sequelize<br><br># Initialize package.json<br>npm init -y<br><br># Install dependencies<br>npm install express express-async-handler body-parser cors pg pg-hstore sequelize @types/node @types/express @types/pg @types/pg-hstore @types/sequelize typescript ts-node --save</pre><blockquote>Now we need a docker-compose.yml file. Inside the restful-api-express-sequelize folder, create a “docker-compose.yml” file</blockquote><p>Open the file and add the following code:</p><pre>version: &quot;3.9&quot;<br><br>services:<br>  db:<br>    image: postgres:13<br>    environment:<br>      - POSTGRES_USER=postgres<br>      - POSTGRES_PASSWORD=mysecretpassword<br>      - POSTGRES_DB=mydatabase<br>    volumes:<br>      - db-data:/var/lib/postgresql/data<br>    networks:<br>      - app-network<br>    ports:<br>      - 5432:5432<br><br>networks:<br>  app-network:<br>    driver: bridge<br><br>volumes:<br>  db-data:</pre><p>This will create a postgres image using docker and will allow you to connect for local development.</p><p>After that, run the following command:</p><pre># inside the restful-api-express-sequelize folder<br><br># this will start the postgres database locally<br>docker-compose up -d</pre><p>2. Creating the Postgres connection:</p><pre>// sequelize.ts<br>import { Sequelize } from &#39;sequelize&#39;;<br><br>const sequelize = new Sequelize(&#39;mydatabase&#39;, &#39;postgres&#39;, &#39;mysecretpassword&#39;, {<br>  host: &#39;localhost&#39;,<br>  dialect: &#39;postgres&#39;,<br>});<br><br>export default sequelize;</pre><p>2. Creating the Postgres model:</p><blockquote>Let’s create the table ‘Task’ and its model that we are going to use forward in our API</blockquote><p>Let’s start with the interface. Create a “task.interface.ts” file</p><pre>// task.interface.ts<br>interface Task {<br>  id: string;<br>  title: string;<br>  description: string;<br>  completed: boolean;<br>}</pre><p>We need the Model now, let’s create a file called “task.model.ts”</p><pre>// task.model.ts<br>import { Model, DataTypes } from &#39;sequelize&#39;;<br>import sequelize from &#39;./sequelize&#39;;<br>import { Task } from &#39;./task.interface&#39;;<br><br>class TaskModel extends Model&lt;Task&gt; implements Task {<br>  public id!: string;<br>  public title!: string;<br>  public description!: string;<br>  public completed!: boolean;<br>}<br><br>TaskModel.init(<br>  {<br>    id: {<br>      type: DataTypes.UUID,<br>      defaultValue: DataTypes.UUIDV4,<br>      primaryKey: true,<br>    },<br>    title: {<br>      type: DataTypes.STRING,<br>      allowNull: false,<br>    },<br>    description: {<br>      type: DataTypes.TEXT,<br>      allowNull: false,<br>    },<br>    completed: {<br>      type: DataTypes.BOOLEAN,<br>      defaultValue: false,<br>    },<br>  },<br>  {<br>    tableName: &#39;tasks&#39;,<br>    sequelize,<br>  }<br>);<br><br>export default TaskModel;</pre><p>3. Implementing the API:</p><blockquote>Now, let’s start implementing the Express.js &amp; TypeScript API. We will create an Express.js Router, define the routes and use the sequelize methods to interact with the Postgres database</blockquote><pre>// server.ts<br>import express, { Request, Response } from &#39;express&#39;;<br>import { Task } from &#39;./task.interface&#39;;<br>import TaskModel from &#39;./task.model&#39;;<br><br>const app = express();<br>app.use(express.json());<br><br>// GET all tasks<br>app.get(&#39;/api/tasks&#39;, async (req: Request, res: Response) =&gt; {<br>  const tasks = await TaskModel.findAll();<br>  res.json(tasks);<br>});<br><br>// POST new task<br>app.post(&#39;/api/tasks&#39;, async (req: Request, res: Response) =&gt; {<br>  const newTask: Task = req.body;<br>  const task = await TaskModel.create(newTask);<br>  res.status(201).json(task);<br>});<br><br>// PUT update task<br>app.put(&#39;/api/tasks/:id&#39;, async (req: Request, res: Response) =&gt; {<br>  const taskId = req.params.id;<br>  const updatedTask: Task = req.body;<br>  await TaskModel.update(updatedTask, { where: { id: taskId } });<br>  const task = await TaskModel.findByPk(taskId);<br>  res.json(task);<br>});<br><br>// DELETE task<br>app.delete(&#39;/api/tasks/:id&#39;, async (req: Request, res: Response) =&gt; {<br>  const taskId = req.params.id;<br>  await TaskModel.destroy({ where: { id: taskId } });<br>  res.sendStatus(204);<br>});<br><br>const PORT = process.env.PORT || 3000;<br>app.listen(PORT, () =&gt; console.log(`Server running on port ${PORT}`));</pre><p><strong>Congratulations !</strong></p><p>You have created a RESTful API using Node.js, Express.js, Docker, TypeScript, Sequelize.</p><p><a href="https://medium.com/@tomescudani">Follow for more</a></p><p><a href="https://www.buymeacoffee.com/dantomescu">☕ Buy me a coffee</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75a32a47a1e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 Junior React.js Developer Interview Questions & Answers]]></title>
            <link>https://medium.com/@tomescudani/10-junior-react-js-developer-interview-questions-answers-c477131b75ee?source=rss-75a079a5c060------2</link>
            <guid isPermaLink="false">https://medium.com/p/c477131b75ee</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Tomescu Dani]]></dc:creator>
            <pubDate>Wed, 26 Jul 2023 14:39:39 GMT</pubDate>
            <atom:updated>2023-07-26T18:00:18.903Z</atom:updated>
            <content:encoded><![CDATA[<p>Here is a list with common interview questions for a Junior React.js Developer position.</p><ol><li><strong>What is React.js?</strong></li></ol><blockquote>React.js is an open-source JavaScript library developed and maintained by Meta. It is primarily used for building user interfaces (UIs) and is commonly used in web development for creating interactive applications.</blockquote><p>2. <strong>How does the Virtual DOM work in React.js?</strong></p><blockquote>Virtual DOM is an important part of React.js as it significantly improves the efficiency of updating the UI. It acts as an abstraction of the actual DOM (Document Object Model), allowing it to compute minimal operations when re-rendering the UI.</blockquote><blockquote>For example, when an element in the real DOM is changed, it will re-render the element and all of its children. This is a slow and inefficient approach. Here the Virtual DOM comes in place and compares the real DOM to a virtual DOM snapshot, it determines what element was changed and only updates that part on the real DOM</blockquote><p>3. <strong>What is prop drilling and how can you avoid it?</strong></p><blockquote>Prop drilling is a situation that occurs when data needs to be passed through multiple children components, even when some intermediate children don’t need the data at all. This can lead to verbose code which can become very hard to maintain.</blockquote><p>Let’s take the following example:</p><pre>// Root component<br><br>function App({ name }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;ProfileBox name={name} /&gt;<br>    &lt;/div&gt;<br>  )<br>}<br><br>// Component Profile Box<br><br>function ProfileBox({ name }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;ProfileFields name={name} /&gt;<br>    &lt;/div&gt;<br>  )<br>}<br><br>// Component ProfileField<br><br>function ProfileField({ name }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;NestedComponent name={name} /&gt;<br>    &lt;/div&gt;<br>  )<br>}<br><br>// Nested Component inside ProfileField<br><br>function NestedComponent({ name }) {<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;My name is {name}&lt;/p&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><p>The component name is passed through many children components without even needing them. This is prop drilling.</p><p>The prop drilling can easily be avoided by using a global state management, such as React Context or Redux</p><p>4. <strong>Explain React.js class component life cycle</strong></p><blockquote>React.js components go through different phases during their ‘lifetime’. The component lifecycle can be divided into the following phases:</blockquote><ol><li>The Mounting Phase: The component is being created and added into the DOM. It has the following methods:</li></ol><ul><li>Constructor: The constructor is called when the component is initialised</li><li>render: The render is responsible for returning the JSX and update the UI</li><li>componentDidMount: This method is called after the component is mounted into the DOM</li></ul><p>2. Updating phase: When a component’s state or props change. It has the following methods:</p><ul><li>shouldComponentUpdate: Called before rendering when new props or state are received</li><li>render: Same as in the mounting phase</li><li>componentDidUpdate: This component is called after the component’s update was flushed into the DOM</li></ul><p>3. Unmounting phase: When the component is removed from the DOM. It includes the following method:</p><ul><li>componentWillUnmount: The method is called just before removing the component and can be used to clean up any resources (e.g. timers)</li></ul><p>5. <strong>Show and example of functional component and class component having the same functionality</strong></p><pre>import React, { useEffect, useState } from &#39;react&#39;;<br><br>const FunctionalComponent = () =&gt; {<br>  const [count, setCount] = useState(0);<br><br>  // componentDidMount and componentDidUpdate are combined in useEffect<br>  useEffect(() =&gt; {<br>    console.log(&#39;Mounted / Updated&#39;);<br>    return () =&gt; {<br>      console.log(&#39;Component will unmount&#39;);<br>    };<br>  }, [count]); // Only re-run the effect if count changes [componentDidUpdate]<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><pre>import React from &#39;react&#39;;<br><br>class ClassComponent extends React.Component {<br>  constructor() {<br>    super();<br>    this.state = { count: 0 };<br>  }<br><br>  componentDidMount() {<br>    console.log(&#39;Component mounted&#39;);<br>  }<br><br>  componentDidUpdate() {<br>    console.log(&#39;Component updated&#39;);<br>  }<br><br>  componentWillUnmount() {<br>    console.log(&#39;Component will unmount&#39;);<br>  }<br><br>  handleIncrement = () =&gt; {<br>    this.setState({ count: this.state.count + 1 });<br>  };<br><br>  render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;p&gt;Count: {this.state.count}&lt;/p&gt;<br>        &lt;button onClick={this.handleIncrement}&gt;Increment&lt;/button&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p>6. <strong>What is conditional rendering in React?</strong></p><blockquote>Conditional rendering is a way of showing different UI elements based on a condition or state.</blockquote><pre>import React from &#39;react&#39;;<br><br>const Greeting = ({ isLoggedIn }) =&gt; {<br>  return isLoggedIn ? &lt;p&gt;Welcome back !&lt;/p&gt; : &lt;p&gt;Please log in.&lt;/p&gt;;<br>};</pre><p>6. <strong>What is useState in React?</strong></p><blockquote>useState is a hook that allows functional components to have and update state</blockquote><pre>import React, { useState } from &#39;react&#39;;<br><br>const Counter = () =&gt; {<br>  const [count, setCount] = useState(0);<br><br>  const handleIncrement = () =&gt; {<br>    setCount(count + 1);<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;button onClick={handleIncrement}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><p>7. <strong>How do you fetch data from a REST API in React?</strong></p><blockquote>Data can be fetched by using ‘fetch’ function or third-party libraries like Axios</blockquote><pre>import React, { useState, useEffect } from &#39;react&#39;;<br><br>const DataFetcher = () =&gt; {<br>  const [data, setData] = useState([]);<br><br>  useEffect(() =&gt; {<br>    // The useEffect callback should never be async, that&#39;s why fetchData is being created and called here<br>    // Alternative would be an IIFE (Immediately Invoked Function Expression)<br>    const fetchData = async () =&gt; {<br>      try {<br>      } catch(e) {<br>        const response = await fetch(&#39;https://api.example.com/data&#39;)<br>        const info = await response.json();<br>        setData(info)<br>      }<br>    }<br>    fetchData()<br>  }, []);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;ul&gt;<br>        {data.map((item) =&gt; (<br>          &lt;li key={item.id}&gt;{item.name}&lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><p>8. <strong>What is React Fragment?</strong></p><blockquote>React Fragment is built-in component used to group multiple elements without introducing an extra DOM node (e.g. a new div)</blockquote><pre>import React from &#39;react&#39;;<br><br>const List = () =&gt; {<br>  // Depending on React.js version &lt;&gt; and &lt;/&gt; can be used<br>  return (<br>    &lt;React.Fragment&gt;<br>      &lt;li&gt;Item 1&lt;/li&gt;<br>      &lt;li&gt;Item 2&lt;/li&gt;<br>      &lt;li&gt;Item 3&lt;/li&gt;<br>    &lt;/React.Fragment&gt;<br>  );<br>};</pre><p>9. <strong>What is Global State Management in React?</strong></p><blockquote>Global State Management is a way of sharing state across different components and avoid prop drilling. It provides a global, centralised approach that can be accessed directly application-wide</blockquote><blockquote>Some ways of achieving Global State Management include using Context API combined with useReducer or an external library like Redux or Mobx</blockquote><p>10. <strong>What are Higher-Order Components in React?</strong></p><blockquote>Higher-Order Components (HOCs) are a design pattern that allows you to extend the functionality of a component by wrapping it into another component. HOCs take a component as input and return a new component with additional props or behaviour</blockquote><pre>import React, { useState } from &#39;react&#39;;<br><br>// Higher-Order Component (HOC) with Hooks<br>const withDynamicStyles = (WrappedComponent) =&gt; {<br>  // The HOC returns a new functional component<br>  const WithDynamicStyles = (props) =&gt; {<br>    const [styles, setStyles] = useState({<br>      fontSize: &#39;16px&#39;,<br>      color: &#39;black&#39;,<br>      fontWeight: &#39;normal&#39;,<br>    });<br><br>    const updateFontSize = (fontSize) =&gt; {<br>      setStyles((prevStyles) =&gt; ({ ...prevStyles, fontSize }));<br>    };<br><br>    const updateColor = (color) =&gt; {<br>      setStyles((prevStyles) =&gt; ({ ...prevStyles, color }));<br>    };<br><br>    const updateFontWeight = (fontWeight) =&gt; {<br>      setStyles((prevStyles) =&gt; ({ ...prevStyles, fontWeight }));<br>    };<br><br>    // The HOC wraps the WrappedComponent and provides additional props or behavior<br>    return (<br>      &lt;div style={styles}&gt;<br>        &lt;WrappedComponent<br>          {...props}<br>          updateFontSize={updateFontSize}<br>          updateColor={updateColor}<br>          updateFontWeight={updateFontWeight}<br>        /&gt;<br>      &lt;/div&gt;<br>    );<br>  };<br><br>  return WithDynamicStyles;<br>};<br><br>// Component that will be wrapped by the HOC<br>const Greeting = (props) =&gt; {<br>  return &lt;h1&gt;Hello, {props.name}!&lt;/h1&gt;;<br>};<br><br>// Use the HOC to create a new component with enhanced functionality<br>const GreetingWithDynamicStyles = withDynamicStyles(Greeting);<br><br>// Usage: Render the enhanced component<br>const App = () =&gt; {<br>  return (<br>    &lt;GreetingWithDynamicStyles name=&quot;John&quot; /&gt;<br>  );<br>};</pre><p>In the example above, the ‘withDynamicStyles’ HOC wraps the ‘Greeting’ component and provides three functions to update CSS styles for the wrapped component</p><p><a href="https://medium.com/@tomescudani">Follow for more</a></p><p><a href="https://www.buymeacoffee.com/dantomescu">☕ Buy me a coffee</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c477131b75ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>