<?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 Dávid Csejtei on Medium]]></title>
        <description><![CDATA[Stories by Dávid Csejtei on Medium]]></description>
        <link>https://medium.com/@codinglikedavid?source=rss-11a03c4f540e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*N5-gdYJ0hs2J5ZsHgIcmMA.jpeg</url>
            <title>Stories by Dávid Csejtei on Medium</title>
            <link>https://medium.com/@codinglikedavid?source=rss-11a03c4f540e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:06:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@codinglikedavid/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[Websocket server and client in Bun(js)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://javascript.plainenglish.io/websocket-server-and-client-in-bun-js-90505e0c4851?source=rss-11a03c4f540e------2"><img src="https://cdn-images-1.medium.com/max/1792/1*shjkHmMljBQI2zbaBK3-gQ.png" width="1792"></a></p><p class="medium-feed-snippet">Bun has a new websocket implementation. This is orders of magnitude faster than any socket solution available in Node. See an example.</p><p class="medium-feed-link"><a href="https://javascript.plainenglish.io/websocket-server-and-client-in-bun-js-90505e0c4851?source=rss-11a03c4f540e------2">Continue reading on JavaScript in Plain English »</a></p></div>]]></description>
            <link>https://javascript.plainenglish.io/websocket-server-and-client-in-bun-js-90505e0c4851?source=rss-11a03c4f540e------2</link>
            <guid isPermaLink="false">https://medium.com/p/90505e0c4851</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[bunjs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Dávid Csejtei]]></dc:creator>
            <pubDate>Thu, 30 Nov 2023 11:35:16 GMT</pubDate>
            <atom:updated>2023-12-04T03:05:28.707Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[What is the most painful part of using TypeScript?]]></title>
            <link>https://javascript.plainenglish.io/what-is-the-most-painful-part-of-using-typescript-62c3a7c4d9c5?source=rss-11a03c4f540e------2</link>
            <guid isPermaLink="false">https://medium.com/p/62c3a7c4d9c5</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Dávid Csejtei]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 18:10:24 GMT</pubDate>
            <atom:updated>2021-01-11T18:10:24.054Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mAVE-XdLfyRWLEjBVZO39A.png" /></figure><h4><strong>What is the most painful part of using TypeScript in general?</strong></h4><p>Handling a value from JavaScript.</p><h4><strong>Why?</strong></h4><p>The reason of having hard times with values coming from an input sources (like an html form) is that <strong>you don’t have the exact data type beforehand</strong>. I mean, you can’t write functions using the input value which could benefit from TypeScript type system because an input value can be anything at that point, another function, a number, a string, an object, or whatever else. That’s why many programmers try to avoid types using the type called “any” in this case. A software developer with advanced TypeScript knowledge never uses the type “any”, because it would be equal to not using TypeScript at all, just would write native JavaScript.</p><p>The question is obvious: <strong>is there any way to put a JavaScript value into the TypeScript context? </strong>The short answer is: yes. For the detailed answer, let’s see an example:</p><p>You have an input value — no matter what source it comes from — for which you want to use a TypeScript context. But how can you pass the unknown type of input value to the type system provided by TypeScript? This is an often misunderstood process, although the flow is very simple.</p><p>First, let’s clarify what our goal is. In JavaScript, in most cases we need some value level validation. We can do this at runtime thanks to the so-called “dynamic type system”. You do not need TypeScript for this. The disadvantage of JavaScript in this case is that we will not have type information before runtime, as the language does not have a static type system. This is exactly what TypeScript adds to our work. TypeScript has only a static type system, meaning it will be present in our program until we compile it. Using this static type system provided by TypeScript in conjunction with the dynamic type system used by JavaScript, we can simulate the capabilities of a strongly typed programming language. In other words, we can validate our values at both runtime and compile time. Let’s turn to our example. Given an input value that will be an object representing a user as we expect.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ef685f8733f6a820d1f5512ae20153b/href">https://medium.com/media/1ef685f8733f6a820d1f5512ae20153b/href</a></iframe><p>The key is the isValidUser function and its use. The isValidUser function is a so-called <a href="https://www.typescriptlang.org/docs/handbook/advanced-types.html">type guard</a>, which is a TypeScript feature. It is used to check a value at the static type level, and then, after checking, to take advantage of the possibilities provided by TypeScript in that block. In practice, this means that if you use this IsValidUser function in an if, you can achieve type security on the given branch of if for the value under test. Why? Because after the test, the TypeScript type system can reliably determine from a given value what type it can be in the future. So in the true branch of if shown in line 29, the static type for user1 will be User, even though this user1 value was previously included as a simple JavaScript value without a static type. If you want, you can use any other check in your isValidUser type guard function, which is good because it allows you to check the given value at compile and run time.</p><p>The type guard function has a special return value, which is nothing more than a structure with a keyword, as you can see in the example. Anything in the body of the type guard function can be anything, the only requirement is to return a logical type. This true / false value will determine whether or not the value under test is of the type specified in the return value. The input parameter of the type guard functions should always be the value under test. The unknown built-in TypeScript type fits perfectly with type guards, as it helps to avoid using the any type.</p><p>If you ask me, you might want to put the type guard functions in files with related type definitions.</p><p>For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c320b88f9103baf8252df542c503bb6/href">https://medium.com/media/3c320b88f9103baf8252df542c503bb6/href</a></iframe><p>In summary, in TypeScript, the official recommendation is to pass a value that does not have a static type to the static type system using the type guard functions properly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62c3a7c4d9c5" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/what-is-the-most-painful-part-of-using-typescript-62c3a7c4d9c5">What is the most painful part of using TypeScript?</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Practical Intro to the Vue 3 Composition API]]></title>
            <link>https://javascript.plainenglish.io/a-practical-intro-to-the-vue-3-composition-api-628b6ff15b2f?source=rss-11a03c4f540e------2</link>
            <guid isPermaLink="false">https://medium.com/p/628b6ff15b2f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[composition-api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue-3]]></category>
            <dc:creator><![CDATA[Dávid Csejtei]]></dc:creator>
            <pubDate>Tue, 29 Dec 2020 10:19:18 GMT</pubDate>
            <atom:updated>2020-12-29T16:26:18.847Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z8gy4NQ4XL_D9bE-ervH4Q.png" /></figure><p>The Composition API is a great way to share application logic between components in Vue.js. Not only can you organize repetitive snippets of code into separate files, you can also make them easily reusable.</p><p>The Composition API allows you to keep your variables reactive in shared snippets of code, which can be a huge improvement over implementations built in previous versions of Vue, even for enterprise-sized applications. According to official documentation, the deployment of the Composition API was necessary because efficient code sharing between components was a problem in larger applications.</p><p>Although there has been a solution to highlight common parts in the past, such as mixin, renderless compontent, or HOC, none of these could provide the same high degree of flexibility as the Composition API. The biggest advantage of this new feature is that we can simultaneously extract the parts that we previously had to implement in the data, computed, and methods parts for a given component (with the Options API). Let’s take a brief example of how to use the Composition API in real-world situations.</p><p>As a first step, create a project using Vue.js (version 3). I will use vue cli for this purpose for the sake of speed. Once the project is complete, delete the example component, we will not need it. Clarify the project structure we will organize the code into. I put my components in the <em>component</em> folder under <em>src</em>, and at the same time I create a <em>services </em>folder into which I pack the reusable but “no-component” code that implements business logic. One file contains one service. If I would have to give an example of common services, there are, for example, services that implement various sorting and filtering or http calls.</p><p>We don’t usually want to write them as components, they can only be parameterized properly, but we want to see the given logic in general, as a module in the code. The Composition API as an implementation solution fits in perfectly with this idea.</p><p>The Composition API introduces a new part to the component code called <em>setup</em>. This is a function that can have 2 parameters, context and props. Within the setup, we can implement the parts that we wrote in the data, computed, and methods sections using the previously known Options API. Here we can define the internal state and functions of our component and here we can also use the common code snippets I call services.</p><p>In a lot of my projects, I needed tables that could be sorted by columns in ascending or descending order. We will create two tables that will use the same director service. This is a great, real-life example of why the Composition API is effective as an idea.</p><p>Of course, in an enterprise-sized project, we would have to go on to outsource all the tabular logic to a generic table component, which then uses the sorting service, but we won’t do that now because the article aims to introduce the Composition API, which will be enough extracting the service code from the tables.</p><p>The aggregation component of our application is called HomePage which only displays the two tables. The two tables are also simple, one listing <strong>users </strong>and the other listing <strong>products</strong>. The Composition API allows me to create a sort operation as a separate service, where I can work with reactive values if I want, which I can then make available in components that use the service.</p><p>In the example, I will store the sort direction in my service’s own reactive variable. I print this order value in both of my table components in the text of the buttons below the data. I will change the sort order only and exclusively within the sort service when necessary and in a clearly visible way, the component will be notified of this change immediately, proving the presence of reactivity.</p><h3>The end result</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/1*MLNo-apiGLuR8sbd6cw9dQ.png" /><figcaption>Result: 2 different tables use the same service to sort data</figcaption></figure><p>The <strong>HomePage </strong>component contains the two tables (and a few lines of css code to highlight tables from the background):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3d18958b97dc10218ff8e7ae9a899d9/href">https://medium.com/media/e3d18958b97dc10218ff8e7ae9a899d9/href</a></iframe><h3>The ProductTable and UserTable components</h3><p>The <strong>ProductTable </strong>component shows a simple table with 3 columns and a button for sorting below. It defines the data rows for the sake of simplicity from the <strong>line of 25</strong>.</p><p><strong>Line 33:</strong> use the order service to get its returned values which are the orderState and orderItems. OrderState is the inside state of the order service contains the direction value (“asc” or “desc”) and OrderItems is the sorting function itself. As you can see the whole sorting logic is separated from the component uses that. Imagine how useful this solution can be with 10 or more services within one component.</p><p><strong>Line 35:</strong> do a sorting with the service at the component “loading time” (see the vue 3 lifecycle methods).</p><p><strong>Line 37:</strong> return with an object contains state (component own - reactive -state), orderItems (sorting function) and orderState (the order service own state with the direction value). <strong>That’s an important moment because the Composition API needs this kind of return in order to work properly.</strong> After you returned with those things, the component’s template can use orderItems and orderState.direction as you can see in the <strong>line of 14</strong>.</p><p><strong>Line 8:</strong> the state can be used in the template in a straightforward way.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea584db6d91ea01cc33106e6bc53094b/href">https://medium.com/media/ea584db6d91ea01cc33106e6bc53094b/href</a></iframe><p>The <strong>UserTable </strong>component is almost identical to the previously analysed ProductTable. The only difference is the data rows at the <strong>line of 25</strong>. This component can benefit from the sorting service just like the ProductTable component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cdc311568bd752d4871b944977dd93e/href">https://medium.com/media/0cdc311568bd752d4871b944977dd93e/href</a></iframe><p>The sort service is nothing special, just a super simple sorting feature. It can sort the given arra of data by the content’s name property. I don’t validate the input values because it doesn’t matter from the Composition API example point of view. The important parts is the reactive state inside the service (or function or whatever you call it) and the return value at the end of the feature.</p><p><strong>Remember: you have to return with EVERYTHING (functions, variables, etc) from the service in order to make it available on the component level.</strong></p><p>The cool thing in Composition API is that the whole logic connected of a feature can be extracted into a separate part because you can “simulate” the data, method and computed features of Vue.js in one single code block if you’d like. With that idea I can made and used my separated sorting feature in any components in the same way.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ecb28c10bf1e695ab5334432a29f732/href">https://medium.com/media/3ecb28c10bf1e695ab5334432a29f732/href</a></iframe><h3>Conclusion</h3><p>I know, I know, it’s a super simple example. The sole purpose of this article is to draw your attention to the biggest benefit of the Composition API. If, like me, you use Vue.js for enterprise softwares, try replacing the usual Options API next time and you won’t be disappointed. What do you think about this topic? Share me your thoughts and experience in the comments. All the best!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=628b6ff15b2f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/a-practical-intro-to-the-vue-3-composition-api-628b6ff15b2f">A Practical Intro to the Vue 3 Composition API</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I’ve learnt from 7,847 enrollments and 136 reviews]]></title>
            <link>https://codinglikedavid.medium.com/what-ive-learnt-from-7-847-enrollments-and-136-reviews-ad4ce16d81c3?source=rss-11a03c4f540e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad4ce16d81c3</guid>
            <category><![CDATA[online-course-creator]]></category>
            <category><![CDATA[instructor]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[self-awareness]]></category>
            <category><![CDATA[experience]]></category>
            <dc:creator><![CDATA[Dávid Csejtei]]></dc:creator>
            <pubDate>Mon, 02 Nov 2020 05:01:02 GMT</pubDate>
            <atom:updated>2020-11-02T05:01:02.592Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-MkM30g3DEE-Yj43h_7Jg.png" /></figure><p>Udemy accepted ‘Your custom React component’ video course <strong>618 days ago</strong> which is my very first video course. It’s a one hour, free tutorial talking about component creation with the React.js JavaScript library. It took about 6 months to create the course while I learnt some important lessons about myself I want to share with you in this article. I belive you can gain from my experience if you want to be an instructor.</p><p><a href="https://www.udemy.com/course/your-custom-react-component/">Free React Tutorial - Your custom React component</a></p><h3>What were my biggest challenges while I was making the course</h3><ul><li>choosing the right style</li><li>explain exactly how something works</li><li>video and sound editing in general</li><li>making the right scripts</li><li>English speaking (English is not my native language)</li></ul><h3>#1 mistake — too small font size</h3><p>As you can see there are some problems in my first course even though I tried to give my best. The most annoying problem is poor video quality. The problem is not with the video resolution but the too small font size. I didn’t realize that I should increase my normally used font size in order to be readable in a video. That was one of the most useful feedback I got from my students. Always check the result on mobile devices too!</p><h3>#2 mistake — too many omissions in the explanation</h3><p>At the beginning of the process, you have to choose a style what you can apply during the course. It defines the form of your screen casts or whether you appear in the video or not. Also, you need to decide whether to record the explanation first or fit it to the video afterwards. After trying to record my explanation live a few times, I realized that it is much harder to focus on solving the example task and its enjoyable explanation at the same time. Therefore, I chose the style of first recording the solution to the task on the video and then later fitting my explanation to it.</p><p>In order to avoid annoying mistakes, I wrote the script for each chapter in advance. That sounds good, but it has a huge downside. When I tried to fit the pre-recorded screen-cast and the post-recorded explanation, it turned out that the pre-recorded text had been terminated much shorter than the given video excerpt. As a result, I was left with two options. The first is to fill in the blank with additional text, the second is to leave it as it is. I didn’t have a good idea of exactly how I could fill in the blanks, so I chose the second option. This can be annoying to the viewer as it can have the effect of having your earphones broken down from one moment to the next.</p><p>I learned a lot from this, in my next course I will consider whether the pre-written text roughly fills in the video section presented. If I think this is not true, I will expand it.</p><h3>Who I was <strong>before </strong>I created this one-hour course</h3><p>From my profession point of view I was a senior full-stack software engineer with serious professional experience behind me. I held some classroom trainings before, but not online. Creating an online course is more different than any other form of teaching. So I was an engineer without any online teaching experience.</p><h3>Who I became <strong>after </strong>I created my first course</h3><p>After I got experience in online teaching, I became a much better engineer. What is the connection between becaming a better engineer and teaching others? The better you can explain (and teach) something the more advanced your knowledge is. What I’ve got from the whole process?</p><ul><li>improved teaching skills</li><li>better English language usage</li><li>improved presentational skills</li><li>the skill of scripting a whole course or describe things</li></ul><p><strong>To sum up:</strong> despite all the mistakes, I am very proud of the first online course of my life. It was a hard, but wonderful adventure. If you want to develop not only your hard skills but also your soft skills, I highly recommend you create some online courses.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad4ce16d81c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Coding styles — small remark]]></title>
            <link>https://medium.com/swlh/coding-styles-small-remark-320de24e7f73?source=rss-11a03c4f540e------2</link>
            <guid isPermaLink="false">https://medium.com/p/320de24e7f73</guid>
            <category><![CDATA[teamwork]]></category>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[principles]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Dávid Csejtei]]></dc:creator>
            <pubDate>Mon, 26 Oct 2020 05:02:47 GMT</pubDate>
            <atom:updated>2020-10-26T05:02:47.889Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rwbhWNY8cKIDnLCp8O67DQ.png" /></figure><h3>Coding styles — small remark</h3><p>I have worked in several different developer teams in the last eight years. All teams had both higher educated and lower educated members. I’m quite sure that you know what I’m talking about. I’ve noticed the following phenomenon: one of the most important kick-off task should be defining the coding style every time we start a new project.</p><h3>What is a coding style</h3><p>Usually we have more than one alternates of writing some code snippet, especially in the script languages. I think we all have our favorites for a validator function, a controller or a DAO, or any other common parts. As an experienced engineer having best practices is a must, nothing wrong with that. But we have to form a team which means we have to adapt to each other’s habits without ruining the project. That’s why we need to define some rules BEFORE the work is started. The first rule is the coding style of the project. The coding style is nothing more than the form of our source code. In JavaScript, you can implement function, classes, blocks in different forms.</p><p>For instance: these are different (coding) styles for JavaScript functions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d0806a1cf941fdd358f3d57e8e8dc78/href">https://medium.com/media/0d0806a1cf941fdd358f3d57e8e8dc78/href</a></iframe><p>Keep in mind that coding style is <strong>not just about syntactical differences</strong>, but the use of classes or code splitting or principles the team keep (DRY, DI, etc.).</p><h3>Why is so important to define the coding style at the beginning of a project</h3><p>Let’s assume that we just do coding on our own and let the project contains different implementation approaches like: there are some parts with IIFE-s AND OOP solutions (classes uses inheritance) AND “Promises with then”-s mixed with async/await forms AND static methods and so on. This way of working causes that the team is going to be in a terrible situation sooner or later. The problem is not that the team uses something or not, the problem is that the team uses different styles without any conventions. This makes the project <strong>unmaintainable</strong>.</p><h3>My recommendation</h3><p>Start your projects with a technical kick-off meeting where the team can decide, among other things, the way of working and the coding style. The outcome of the discussion should be a Code Of Conduct (CoC) paper (or whatever you call it) contains rules of the project. This paper will be incredibly useful when a newcomer arrives or someone forget some part of the ruleset. Sometimes we need to make changes in our project rules because it comes out we have better ideas. That’ normal, nothing wrong with that. Keep your CoC up to date.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=320de24e7f73" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/coding-styles-small-remark-320de24e7f73">Coding styles — small remark</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[(Type) ORM — TypeScript]]></title>
            <link>https://medium.com/swlh/type-orm-typescript-b3a75c702f89?source=rss-11a03c4f540e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3a75c702f89</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[orm]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Dávid Csejtei]]></dc:creator>
            <pubDate>Mon, 19 Oct 2020 04:03:08 GMT</pubDate>
            <atom:updated>2020-10-23T14:10:08.453Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E7xRNq4jb6JS4YZsk2lXTQ.png" /></figure><h3>(Type) ORM — TypeScript</h3><p>In the last couple of years I used ORM (Object-Relational Mapping) in my Node.js projects a lot. Every time when I had to work with any relational databases I just grapped <a href="https://sequelize.org/master/">SequelizeORM</a> to make my life easier. Unfortunately, even though Sequelize has TypeScript support according to its documentation, my experience wasn’t good at all with that. If you ask me, Sequelize is a great option in Node.js if you don’t use TypeScript, but I had to find a better option for my TypeScripted projects. Two day ago I read this library’s name somewhere: <a href="https://typeorm.io/">TypeORM</a>.</p><p><strong>I wish I had a library which</strong>:</p><ul><li>REALLY uses TypeScript</li><li>has easy configuration process</li><li>supports advanced code splitting (DAO-s or Repository-s, models, migrations, etc.)</li><li>supports multiple database engines</li><li>has some kind of cli support (create models / entities, etc.)</li></ul><h3>TypeORM — first impressions</h3><p>First of all, I went over the official documentation. It was easy to follow and it had enough examples as well. After that I created a new Node.js project with Typescript and Express and installed TypeORM. I read about the CLI support of TypeORM, but I wanted to do things manually for the first time to understand every little details.</p><p>My goal was to make a POC project to check how many points could fulfilled from my wish list. This little project can connect to an existing relational database running on a PostgreSQL engine and get all the rows from a table called user. Moreover, the project provides an API to work with.</p><h3>Here is my POC (Proof of Concept) process:</h3><ol><li>Added the <em>ormconfig.json</em> <strong>configuration </strong>file in the project root</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c62b8c995c9b4d6c8367db8edc8e2179/href">https://medium.com/media/c62b8c995c9b4d6c8367db8edc8e2179/href</a></iframe><p>2. I <strong>made </strong>a <strong>db </strong>folder in my project root and add the following <strong>directories </strong>into that: <em>entities</em>, <em>migrations</em>, <em>repositories </em>and <em>subscribers</em>.</p><p>3.<strong> Built up</strong> the database <strong>connection </strong>and<strong> initialize an express instance </strong>in my application entry point (<em>index.ts</em>) using the ormconfig.json file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c953ef961a403dd64c0faab22e9c4f4b/href">https://medium.com/media/c953ef961a403dd64c0faab22e9c4f4b/href</a></iframe><p>4. <strong>Created </strong>the first <strong>entity</strong> file (<em>db/entities/User.ts</em>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/42984f33868000e0955a080022772de4/href">https://medium.com/media/42984f33868000e0955a080022772de4/href</a></iframe><p>5. <strong>Made </strong>a custom <strong>repository for Users</strong> (<em>db/repositories/UserRepository.ts</em>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2abb8526d1110543f1007bb4beec3fdc/href">https://medium.com/media/2abb8526d1110543f1007bb4beec3fdc/href</a></iframe><p>6. <strong>Created </strong>a <strong>custom subscriber for User entity </strong>just to try this feature too (<em>db/subscribers/UserSubscriber.ts</em>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f30fdeb85f483b5c674806c9ac11a3f4/href">https://medium.com/media/f30fdeb85f483b5c674806c9ac11a3f4/href</a></iframe><p>7. Made my first <strong>controller endpoint</strong> (<em>controllers/GetAllUsers.ts</em>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d489d2f4cfa7b585e19fa77a0aa05513/href">https://medium.com/media/d489d2f4cfa7b585e19fa77a0aa05513/href</a></iframe><p>8. Extends index.ts with my first endpoint on GET users/all route (in the index.ts):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a22219a54deec6b5e938fae493db770a/href">https://medium.com/media/a22219a54deec6b5e938fae493db770a/href</a></iframe><p>9. Despite I said I didn’t want to use the CLI support of TypeORM making the <strong>migration file for User</strong> was an exception. That’s because all migrations have to start with a timestamp, so it was easier to generate a migration file through the CLI application: <br><em>typeorm migration:create -n DefaultUsers -d src/db/migrations.</em></p><p>I didn’t use migration so just leaved empty in this POC. After I read the migration part of the documentation it was obvious that migrations could do what I need that for.</p><p>10. Started application and called the /users/all endpoint to make sure that it was working… and it worked smoothly. Perfect!</p><h3>Conclusion — TypeORM seems usable</h3><p>The POC proved me that the <a href="https://typeorm.io/">TypeORM </a>can be a good solution for the ORM problem in TypeScript. Let’s check my wish list again:</p><ul><li>REALLY uses TypeScript 🗹</li><li>has easy configuration process 🗹</li><li>supports advanced code splitting (DAO-s or Repository-s, models, migrations, etc.) 🗹</li><li>supports multiple database engines 🗹</li><li>has some kind of cli support (create models / entities, etc.) 🗹</li></ul><p>To be honest, I can’t wait to apply this library in my next project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3a75c702f89" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/type-orm-typescript-b3a75c702f89">(Type) ORM — TypeScript</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Unit Test Express Middleware]]></title>
            <link>https://javascript.plainenglish.io/how-to-unit-test-express-middleware-typescript-jest-c6a7ad166e74?source=rss-11a03c4f540e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6a7ad166e74</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[jest]]></category>
            <dc:creator><![CDATA[Dávid Csejtei]]></dc:creator>
            <pubDate>Fri, 16 Oct 2020 10:24:21 GMT</pubDate>
            <atom:updated>2020-10-23T12:43:46.589Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f9yppJYsYKsgmMN9wOXNyQ.png" /></figure><p>If you use Test Driven Development for your Node.js project uses Express library, you need to write unit tests among other things. As I experienced, testing code parts which use third party libraries are usually difficult for less experienced developers. The key aspect of effective unit testing is define boundaries of the business logic to be tested.</p><h4>Test the business logic, and nothing else</h4><p>When I write unit tests including any structural items of the Express library, it produces me I have to <strong>avoid testing the library itself</strong>. It’s not my job. Rather than only my business logic needs to be tested. As for the middleware, it’s the logic inside the middleware function. The input parameters are coming from the Express library, so you need to mock or stub them.</p><h4>Mock or stub only the needed parts coming from Express, nothing more</h4><p>An Express middleware is a special function which has three parameters: a request, a response and a next function. These are coming from the library flow, and you just need to wire the middleware to the proper level (application, router, etc.).</p><h4>Stay typed (use official Express types)</h4><p>The most common problem with typescript is that a lack of knowledge of the type system that forces the programmer to try to bypass the own type system instead of taking advantage of its potential. Don’t do that! Express provides you its types for the requests (Request), responses (Response) and even for the next function (NextFunction).</p><p>The only problem with Request and Response types when tests come into the picture is that they have so many required attributes which means you would have to define all of them to pass the type check. That wouldn’t be effective at all. That’s why you should learn the Utility types from TypeScript. These are great for customizing existing types for your needs.</p><p>In this case I would use just some parts of the Request and Response types, that’s why the Partial utility type helps me this time. Partial with the generic type parameter means ‘some subset of the type comes as type parameter’.</p><h4>Simple example — authorization header guard middleware</h4><p>Let’s see a simple example. A middleware checks if the request contains authorization header or not. If it is, you just let the flow runs through the middleware but if the header is missing send an error response immediately.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50311e7a970b27b0c1e46668412d132d/href">https://medium.com/media/50311e7a970b27b0c1e46668412d132d/href</a></iframe><p>Here is the unit tests with Express Request, Response and Next function mocks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13a23093218a0c1c13743225160a39bf/href">https://medium.com/media/13a23093218a0c1c13743225160a39bf/href</a></iframe><h4>Keep the DRY principle (Don’t Repeat Yourself)</h4><p>Don’t write test cases over each other. For instance: You want to test your middleware with a string input property in your request body. In this scenario don’t write multiple different test cases with the same string type if these don’t differ from your business logic point of view. At first sight it doesn’t seem to be a serious problem but believe me, you can generate high amount of code smell that nobody wants to have in their projects. Just keep this advice in mind.</p><h4>Practice, practice a lot</h4><p>Writing effective automated tests is one of the hardest software development challenge you can choose. You can easily feel you don’t have any concept of how to do your tests in the proper way. That’s normal. I think the only way to improve testing skills is practice. Write as much as unit (or integrated, or whatever) tests as you can, make mistakes and learn from them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6a7ad166e74" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-unit-test-express-middleware-typescript-jest-c6a7ad166e74">How to Unit Test Express Middleware</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Information gathering]]></title>
            <link>https://codinglikedavid.medium.com/information-gathering-ad5ae48234a6?source=rss-11a03c4f540e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad5ae48234a6</guid>
            <dc:creator><![CDATA[Dávid Csejtei]]></dc:creator>
            <pubDate>Wed, 20 Dec 2017 12:33:36 GMT</pubDate>
            <atom:updated>2017-12-20T13:06:06.712Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>ping</strong></h4><p>Send and receive ICMP echo request packages and get responses</p><p>result: IP addresses belongs to domain, maximum frame size on the network</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/993bf9bc66e7414d9d3503cd5f95bd3e/href">https://medium.com/media/993bf9bc66e7414d9d3503cd5f95bd3e/href</a></iframe><h4>traceroute</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad5ae48234a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to find and list files larger than 10 MB in Ubuntu]]></title>
            <link>https://codinglikedavid.medium.com/how-to-find-and-list-files-larger-than-10-mb-in-ubuntu-4ef86d046b82?source=rss-11a03c4f540e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ef86d046b82</guid>
            <dc:creator><![CDATA[Dávid Csejtei]]></dc:creator>
            <pubDate>Wed, 20 Dec 2017 10:00:46 GMT</pubDate>
            <atom:updated>2017-12-20T10:05:13.407Z</atom:updated>
            <content:encoded><![CDATA[<p>Find and list (size given in MB not in KB) files larger than 10 MB in /home directory:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fe6dfac59227684c86071bde7b72018/href">https://medium.com/media/5fe6dfac59227684c86071bde7b72018/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ef86d046b82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set MySQL default charset in Windows XAMP]]></title>
            <link>https://codinglikedavid.medium.com/how-to-set-mysql-default-charset-in-windows-xamp-ec8dc30f9da5?source=rss-11a03c4f540e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec8dc30f9da5</guid>
            <category><![CDATA[windows-7]]></category>
            <category><![CDATA[xampp]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Dávid Csejtei]]></dc:creator>
            <pubDate>Sun, 10 Dec 2017 19:56:11 GMT</pubDate>
            <atom:updated>2017-12-10T19:56:11.855Z</atom:updated>
            <content:encoded><![CDATA[<p>MySQL has the latin1_swedish_ci as default charset but I need to set utf-8.</p><p>Append the following lines to the end of my.ini:</p><blockquote>[mysqld] <br>character-set-server=utf8<br>collation-server=utf8_general_ci</blockquote><p>Now you have to restart the MySQL server to apply changes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec8dc30f9da5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>