<?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: Maciej Wakuła</title>
    <description>The latest articles on DEV Community by Maciej Wakuła (@adderek).</description>
    <link>https://dev.to/adderek</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%2F930226%2F9b028237-45fb-4be4-b3e7-3ca4df1d885c.jpeg</url>
      <title>DEV Community: Maciej Wakuła</title>
      <link>https://dev.to/adderek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adderek"/>
    <language>en</language>
    <item>
      <title>JavaScript turbo startup</title>
      <dc:creator>Maciej Wakuła</dc:creator>
      <pubDate>Mon, 23 Oct 2023 05:36:14 +0000</pubDate>
      <link>https://dev.to/adderek/javascript-turbo-startup-k4p</link>
      <guid>https://dev.to/adderek/javascript-turbo-startup-k4p</guid>
      <description>&lt;p&gt;Note: Some topics might be intentionally skipped or not giving full picture to speed you up into JavaScript.&lt;/p&gt;

&lt;p&gt;JavaScript language can run in a browser (ex. chrome, firefox, safari) or server (ex. node, bun). Your code runs command after command (serially) with no multithreading. Common mistake is to run long method (ex. "FOR" iteration loop) too long in a row blocking page or server.&lt;/p&gt;

&lt;p&gt;Most often used IDE is currently visual studio code due to low price (free), great ecosystem and integration, plenty of features out of the box and plugins.&lt;/p&gt;

&lt;p&gt;JavaScript has plenty of frameworks and modules (libraries) hosted on &lt;a href="http://www.npmjs.com"&gt;npmjs.com&lt;/a&gt;. Most cases you pick one framework for the front-end (browser), one for the back-end (server) and stick to them. It is important to separate front-end from back-end as modules are loaded and executed differently what in the end leads to different specialization of the tools.&lt;/p&gt;

&lt;p&gt;Few projects to start: &lt;a href="https://expressjs.com/"&gt;express web server&lt;/a&gt;, &lt;a href="https://github.com/socketio/socket.io"&gt;socket.io browser-server communication&lt;/a&gt;, &lt;a href="https://www.passportjs.org/"&gt;passport.js authentication&lt;/a&gt; to login to your page, &lt;a href="https://nextjs.org/"&gt;next.js&lt;/a&gt; framework, &lt;a href="https://nestjs.com/"&gt;nest.js&lt;/a&gt;  framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Language versions confusion.&lt;/strong&gt;&lt;br&gt;
JavaScript evolves dynamically and many features are being constantly introduced. Developers usually can use a transpiler, that is an application to translate code from whatever language (newest version of JavaScript, Typescript, coffeescript, etc.) into an older version of JavaScript supported by their browser/server. The most important distinction is to JavaScript, or rather EcmaScript with different versions (having a number of an equivalent year) and other languages. Things get much more complicated when you read about the module loading, code execution and more complex topics.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Git commit messages</title>
      <dc:creator>Maciej Wakuła</dc:creator>
      <pubDate>Thu, 22 Jun 2023 16:40:27 +0000</pubDate>
      <link>https://dev.to/adderek/git-commit-messages-32ie</link>
      <guid>https://dev.to/adderek/git-commit-messages-32ie</guid>
      <description>&lt;p&gt;Hints for writing git commit messages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;commit message has a header, then optional empty line followed by longer description

&lt;ul&gt;
&lt;li&gt;header is a 1-line abstract summary&lt;/li&gt;
&lt;li&gt;header can start with a prefix, ex. "fix:", "feat:", "BREAKING" - see &lt;a href="https://conventionalcommits.org"&gt;https://conventionalcommits.org&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;keep it short, avoid plural, "the", "an", dot, etc.&lt;/li&gt;
&lt;li&gt;examples: "add lib X", "fix #123", "add default cfg"&lt;/li&gt;
&lt;li&gt;longer description can be added after an empty separator line - use it to provide details for whoever might need to check this commitin the future, link to tickets, features, links, files&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;git log --oneline&lt;/code&gt; to show only the commit headers&lt;/li&gt;
&lt;li&gt;as long as it is on your local branch - use rebase to keep your commits on the top of other changes&lt;/li&gt;
&lt;li&gt;after someone might have used it (ex. you merged it to develop), avoid rebase&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
    </item>
    <item>
      <title>Asynchronous processing in JavaScript</title>
      <dc:creator>Maciej Wakuła</dc:creator>
      <pubDate>Sat, 15 Apr 2023 13:48:36 +0000</pubDate>
      <link>https://dev.to/adderek/asynchronous-processing-in-javascript-5adh</link>
      <guid>https://dev.to/adderek/asynchronous-processing-in-javascript-5adh</guid>
      <description>&lt;p&gt;This is a continuation of &lt;a href="https://dev.to/adderek/intro-to-node-and-npm-3apd"&gt;Introduction to node and npm&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;JavaScript engines are generally single-threaded. Long call processing would normally block any other call but we leverage asynchronous processing to interrupt currently executed procedure allowing engine to switch between the jobs. Behind the scenes Input/Output is multi-threaded.&lt;br&gt;
There are many ways JS developers could achieve effects similar to multi-threading.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. How asynchronous processing works
&lt;/h2&gt;

&lt;p&gt;You send a message (ex. a request to process a resource like "add a new user to the system") and usually get a confirmation that the request was received. In REST this might be 202 (Accepted) and "location" header, in messaging systems a valid &lt;em&gt;ID of the request&lt;/em&gt;.&lt;br&gt;
But the message is only queued for processing, not yet processed.&lt;/p&gt;

&lt;p&gt;Whenever system has free resources (ex. is not doing anything more important or queued before your request) then your request could be processed. This takes usually between milliseconds and weeks. It could be for example a request to add a new bank account that must be verified by someone.&lt;/p&gt;

&lt;p&gt;When requesting something, often a feedback (confirmation and/or return data) is expected. This is usually done using message sent by the processing system to a place you can access. Often it would contain "correlation-id" that is the &lt;em&gt;ID of the request&lt;/em&gt; to indicate it is a response to previous request. Simply saying: We cannot send response (not yet) but we can send instruction (ex. URL) to check if it was already finished.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Several attempts to use asynchronous processing
&lt;/h2&gt;
&lt;h3&gt;
  
  
  3.1. How the code execution gets postponed
&lt;/h3&gt;

&lt;p&gt;In JavaScript calls could be postponed whenever you use a promise (or async/await which is using promises behind the scene).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function log1(msg) {
  await console.log(msg);
}
async function log2(msg) {
  console.log(msg);
}
function log3(msg) {
  console.log(msg);
}
function log4(msg) {
  return new Promise(resolve=&amp;gt;console.log(msg));
}

setTimeout(()=&amp;gt;log1(1), 0);
setTimeout(()=&amp;gt;log2(2), 0);
setTimeout(()=&amp;gt;log3(3), 0);
setTimeout(()=&amp;gt;log4(4), 0);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usually prints 1,2,3,4 as expected.&lt;br&gt;
Internally those are 4 different calls scheduled to happen with 0ms delay (no delay). And the order of execution doesn't need to keep the sequence.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;log1&lt;/code&gt; is async (returns a promise) and stops execution when calling &lt;code&gt;console.log&lt;/code&gt; because there is &lt;code&gt;await&lt;/code&gt;. Once called, the promise is not yet fulfilled - it would be after &lt;code&gt;console.log&lt;/code&gt; returned,then &lt;code&gt;log1&lt;/code&gt; could continue, and finally it returns. You are sure that &lt;code&gt;console.log&lt;/code&gt; returns before &lt;code&gt;log1&lt;/code&gt; gets fulfilled (only because there is "await").&lt;/p&gt;

&lt;p&gt;&lt;code&gt;log2&lt;/code&gt; is async (returns a promise) and triggers &lt;code&gt;console.log&lt;/code&gt; and returns. You have no guarantee that &lt;code&gt;console.log&lt;/code&gt; prints output before &lt;code&gt;log2&lt;/code&gt; gets fulfilled.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;log3&lt;/code&gt; is just a function. The &lt;code&gt;console.log&lt;/code&gt; might be scheduled but &lt;code&gt;log3&lt;/code&gt; returns and continues to execute your code. The JavaScript thread is blocked until it returns (though it can schedule some promises).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;log4&lt;/code&gt; returns a promise. Its execution could be delayed (then you see that returned promise is "pending" until it gets "fulfilled").&lt;/p&gt;

&lt;p&gt;Think about it thoroughly and you could also omit &lt;code&gt;setTimeout&lt;/code&gt; in 3 out of 4 cases - then call is made and a "pending promise" is returned. In fact the case of &lt;code&gt;log3&lt;/code&gt; is probably most dangerous.&lt;/p&gt;

&lt;p&gt;If you are using node, then internally &lt;a href="https://github.com/libuv/libuv"&gt;libuv&lt;/a&gt; is used for calls and also for anything like input/output (ex. to print something onto the console).&lt;/p&gt;
&lt;h3&gt;
  
  
  3.2. Calling other applications
&lt;/h3&gt;

&lt;p&gt;You can sent a request to another system, service or application. You can send a REST request and should wait for the response (even "Accepted" when task is only queued). Or publish this to a queue yourself.&lt;/p&gt;
&lt;h3&gt;
  
  
  3.3. Workers
&lt;/h3&gt;

&lt;p&gt;Node can run parallel instances of node called "workers". Workers can act as a parallel process to perform heavy work without blocking the main thread.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. What to look at
&lt;/h2&gt;
&lt;h3&gt;
  
  
  4.1. Intervals
&lt;/h3&gt;

&lt;p&gt;You can schedule a method to be called with a fixed interval:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let counter = 0;
let intervalHandle = undefined;
const intervalInMilliseconds = 10;

function myMethod() {
  counter++;
  for(let i = 0; i &amp;lt; 9999; i++){console.log(i);}

  if(counter &amp;gt; 10) {
    clearInterval(intervalHandle);
    intervalHandle = null;
  }
}

intervalHandle = setInterval(myMethod, intervalInMilliseconds);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could expect that it prints number from 0 to 9999 every 10ms until 10 iterations are made within 100ms.&lt;br&gt;
The issue is that you have no guarantee that methods would be called every 10ms. This could lead to 2 problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your method could be called more than once at the same time (if it is using asynchronous processing internally)&lt;/li&gt;
&lt;li&gt;Your method could be executed with longer interval (it needs to print the numbers first)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A bit corrected code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let counter = 0;
const minimumIntervalInMilliseconds = 10;
function myMethod() {
  counter++;
  for(let i = 0; i &amp;lt; 9999; i++){console.log(i);}

  if(counter &amp;lt;= 10) {
    setTimeout(myMethod, minimumIntervalInMilliseconds);
  }
}

setTimeout(myMethod, minimumIntervalInMilliseconds);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Dangers of single-threaded app
&lt;/h2&gt;

&lt;p&gt;If your application runs inside a docker container that has a healthcheck and restarts whenever healthcheck is not responded (ex. timeout 1s, interval 1s), then any job blocking main thread for 1000ms would result in container being restarted.&lt;/p&gt;

&lt;p&gt;If your app runs on kubernetes and your is blocked over the timeout threshold then your application might be "disconnected" (readiness probe) or restarted (liveness probe).&lt;/p&gt;

&lt;p&gt;If you are connected to a queue (ex. kafka or RabbitMQ) and your application is busy for the timeout (ex. 3000ms for kafka subscriber) then your application will be kicked-out and considered "dead". I have seen this scenario where developers tried to update RabbitMQ and its libraries searchign for an issue in the server - where the cause was in the node code.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>node --save-*</title>
      <dc:creator>Maciej Wakuła</dc:creator>
      <pubDate>Tue, 14 Mar 2023 21:32:10 +0000</pubDate>
      <link>https://dev.to/adderek/node-save--1ci4</link>
      <guid>https://dev.to/adderek/node-save--1ci4</guid>
      <description>&lt;h2&gt;
  
  
  Content
&lt;/h2&gt;

&lt;p&gt;This article roughly describes node package management concepts especially focusing on dependencies management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Node
&lt;/h3&gt;

&lt;p&gt;The node is a single-threaded asynchronous server-side runtime environment for JavaScript (you can run JavaScript without a web browser) using "V8" JavaScript runtime written in C++ by Google.&lt;/p&gt;

&lt;h3&gt;
  
  
  Node packages
&lt;/h3&gt;

&lt;p&gt;JavaScript is very (too much?) flexible resulting in millions of libraries (modules) being created and published (over 1.3 million at the moment this article was created).&lt;/p&gt;

&lt;p&gt;Project often include many modules - which then include others. This creates a very complex web of dependencies that needs to be solved in order to run the software.&lt;/p&gt;

&lt;h3&gt;
  
  
  NPM - Node Package Manager
&lt;/h3&gt;

&lt;p&gt;Node comes with its own solution to manage, publish, download, install and also share modules (packages). There are many solid alternatives but &lt;code&gt;npm&lt;/code&gt; became a part of the node (while npm is an installable module itself).&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of dependencies
&lt;/h2&gt;

&lt;p&gt;Node currently defines following types of dependencies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;normal dependencies - meant to run on production environment&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;you install them using &lt;code&gt;npm install --save {dependencyName}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;keep them as least as possible&lt;/li&gt;
&lt;li&gt;whenever someone installs your module - they would also install those dependencies&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;development dependencies - to be used during development only (but it is used also for testing)&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;whatever you need for your development and testing&lt;/li&gt;
&lt;li&gt;assume they are not present on production environment&lt;/li&gt;
&lt;li&gt;you install them using &lt;code&gt;npm install --save-dev {packageName}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;when installing on non-production environment those gets installed together with your module&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;peer dependencies - which are not installed for the module but must be provided by your application

&lt;ul&gt;
&lt;li&gt;you expect them to be provided, not installed by your module&lt;/li&gt;
&lt;li&gt;often developers start with dependencies and devDependencies optimizing them later&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each module (package) has a version. NPM is using SemVer (Semantic Versioning). Version has 3 numbers and optionally extra part:&lt;br&gt;
&lt;code&gt;{major}.{minor}.{patch}&lt;/code&gt;, ex. &lt;code&gt;1.2.3&lt;/code&gt; where&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;major should be increased whenever it can break existing code (increase it to indicate that update is not strightforward and might require code change)&lt;/li&gt;
&lt;li&gt;minor is to indicate new features (with backward compatibility)&lt;/li&gt;
&lt;li&gt;patch is to indicate non-functional changes (logic remains the same but for example bugfix is applied)
Version can have an optional suffix:
&lt;code&gt;{major}.{minor}.{patch}-{suffix}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;suffix is often either

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;{name}.{number}&lt;/code&gt; allowing you to have multiple "branches" of builds&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{number}&lt;/code&gt; to just indicate build number&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When installing a package dependency to your application it installs by default "latest". When updating it tries to use same major version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Traps
&lt;/h2&gt;

&lt;p&gt;Developers often release new breaking change with patch version or publish updated version with incorrect SemVer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tag pre-id
&lt;/h2&gt;

&lt;p&gt;When releasing new version of package to npmjs.org you always publish it under a "tag". The main one is "latest". The only hint for alternative names is that "next" is often used for  development/unstable releases. Often used tags are used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;to indicate a version line "npm" (ex. "latest" for current version, "next" for the unstable one in development, "latest-2" to indicate version 2.x which might still receive updates)&lt;/li&gt;
&lt;li&gt;to indicate flavor (ex. "stable", "unstable" but also "latest")&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By default most recent "latest" version is installed and later updated to newer "latest" with same major number.&lt;/p&gt;

&lt;h2&gt;
  
  
  Different versions in same project
&lt;/h2&gt;

&lt;p&gt;Imagine using &lt;code&gt;libA@1.0.1&lt;/code&gt; and &lt;code&gt;libB@1.0.0&lt;/code&gt; but then &lt;code&gt;libB&lt;/code&gt; depends on &lt;code&gt;libA@1.0.0&lt;/code&gt;.&lt;br&gt;
Assuming &lt;code&gt;libA@1.0.1&lt;/code&gt; is backward compatible - npm can install &lt;code&gt;libA@1.0.1&lt;/code&gt; and &lt;code&gt;libB@1.0.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But let's change it a bit: use &lt;code&gt;libA@2.0.0&lt;/code&gt; and &lt;code&gt;libB@1.0.0&lt;/code&gt; (we know it requires &lt;code&gt;libA@1.0.1&lt;/code&gt;). NPM would install both versions of &lt;code&gt;libA&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Some packages (ex. react) would cause multiple problems when different versions are installed all together. Others might create a cross-dependency hell (libA depends on libB and libB depends on libA) what is an implementation bug (but works so often happens).&lt;/p&gt;

&lt;h2&gt;
  
  
  Checking your dependencies
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;npm outdated&lt;/code&gt; shows outdated dependencies: whether any newer compatible exists, and also any newer (non-compatible)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm audit&lt;/code&gt; to see if your dependencies contain any known vulnerabilities&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm update&lt;/code&gt; is a risky operation updating your dependencies to "newer versions that **shouldBB be compatible"&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  My personal opinion
&lt;/h2&gt;

&lt;p&gt;Huge risk of package marked as compatible (while it is not) discourage developers from updates increasing likeliness of outdated software and technical debt creation.&lt;br&gt;
Having development dependencies leads to scenario where test build differs from target artifact (not reliable tests).&lt;br&gt;
Together the approach is risky and dirty but you must deal with it when working with node. Node has a huge win of being single-threaded but asynchronous nicely fitting to contenerization approach on cloud. Kotlin (soon Java with loom) attempts to offer same functionality but still generally requires more powerful hardware. Node is still a good option for microservices and frontend.&lt;/p&gt;

&lt;p&gt;This is just an introduction to the dependencies management hell in NPM.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Introduction to node and npm</title>
      <dc:creator>Maciej Wakuła</dc:creator>
      <pubDate>Sun, 30 Oct 2022 19:54:05 +0000</pubDate>
      <link>https://dev.to/adderek/intro-to-node-and-npm-3apd</link>
      <guid>https://dev.to/adderek/intro-to-node-and-npm-3apd</guid>
      <description>&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1.1. Target audience
&lt;/h3&gt;

&lt;p&gt;This post is created especially for beginners and people who know some programming but are not familiar with node or npm.&lt;/p&gt;

&lt;h3&gt;
  
  
  1.2. Topics (not) covered
&lt;/h3&gt;

&lt;p&gt;This is merely an introduction to node and npm (node package manager). It &lt;strong&gt;does not&lt;/strong&gt; mention alternatives.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Node
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1. About node
&lt;/h3&gt;

&lt;p&gt;Node is a server-side runtime built on top of Google Chrome V8 javascript engine.&lt;br&gt;
Node simply runs your javascript code on the server (without any browser window).&lt;/p&gt;
&lt;h3&gt;
  
  
  2.2. Usage
&lt;/h3&gt;

&lt;p&gt;Simple usage: &lt;code&gt;node myscript.js&lt;/code&gt;&lt;br&gt;
Usually main file is called &lt;code&gt;index.js&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2.3. Setup
&lt;/h3&gt;

&lt;p&gt;You can download node from &lt;a href="https://nodejs.org/en/"&gt;https://nodejs.org/en/&lt;/a&gt;&lt;br&gt;
You could also run it within a container, ex. by running &lt;code&gt;docker run --rm -it node:lts bash&lt;/code&gt; (assuming you have docker installed).&lt;/p&gt;
&lt;h3&gt;
  
  
  2.4. Important notes about threading for developer not familiar with JavaScript
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;JavaScript is single threaded by design.&lt;/strong&gt; It means that all the commands are executed sequentially &lt;strong&gt;but every chunk can be executed out of order.&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Input/Output operations are multi-threaded though.&lt;/strong&gt;&lt;br&gt;
Knowledge of multi-threading from other languages is making things harder for you.&lt;br&gt;
&lt;strong&gt;Try to divide your code into smaller chunks that end quickly.&lt;/strong&gt; Example trap waiting for you is a "for" iteration which executed time consuming operation - you would block entire node process until iteration is completed.&lt;/p&gt;

&lt;p&gt;Node is using either promises (a method call that is postponed but you could plan further calls based on its result) or async/await (which internally works on promises). See code example at the end.&lt;/p&gt;

&lt;p&gt;If you are thinking that single-threading is bad then think again. Developer has possibly better control over the process than with multithreading one and you don't need to create a separate thread. Java is currently trying to implement similar mechanism with project &lt;a href="https://openjdk.org/projects/loom/"&gt;loom&lt;/a&gt;. This solution brings some dangers though as developer can easily block the thread so your critical handlers (which are excepted to handle ex. keepalive requests) could not be called. Common unwanted effect is that your application gets disconnected from servers (database, rabbitMQ, kafka, etc.) or killed (ex. docker health checks).&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Node Package Manager (npm)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/"&gt;https://www.npmjs.com/&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  3.1. What is npm
&lt;/h3&gt;

&lt;p&gt;It is a manager application used to install, remove, update, check, ... your code &lt;strong&gt;but also an repository of immense amount of libraries and frameworks&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  3.2. Npm packages
&lt;/h3&gt;

&lt;p&gt;You could create own projects and publish them for free onto npmjs.org with public access (but also private access is available for paid accounts).&lt;br&gt;
Projects that consist of several packages often are grouped into organizations like &lt;a href="https://www.npmjs.com/package/@babel/core"&gt;@babel&lt;/a&gt;. Organizations are prefixed with "@" character.&lt;/p&gt;

&lt;p&gt;The npm ecosystem is very rich and has many packages. Amount of them is often used in jokes like with the &lt;a href="https://npmdrinkinggame.party/"&gt;npm drinking game&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  3.3. Npm package versioning
&lt;/h3&gt;

&lt;p&gt;Packages are released with tags, default tag is "latest". Any custom tag can be created but often tag "next" is used for any "unstable" releases.&lt;/p&gt;

&lt;p&gt;Package versions should follow &lt;a href="https://semver.org/"&gt;SemVer&lt;/a&gt;. Example number is &lt;code&gt;1.2.3&lt;/code&gt; (major.minor.patch).&lt;br&gt;
You should increase major number when introducing breaking changes (anything that could break apps using your package).&lt;br&gt;
Minor number should be used when adding new features without breaking existing functionality.&lt;br&gt;
Patch number is used for small bugfixes that do not break logic nor add new features.&lt;/p&gt;

&lt;p&gt;By default when installing a package you would install most recently released version from "latest" tag (even if its number is lower than previously released one).&lt;br&gt;
"Unstable" releases should be released under alternative tag and have additional suffix, ex. &lt;code&gt;1.2.4-next.0&lt;/code&gt; to indicate that this is a pre-release version of upcoming &lt;code&gt;1.2.4&lt;/code&gt; version under tag &lt;code&gt;next&lt;/code&gt;, candidate number 0.&lt;br&gt;
When auto-updating packages npm would try to stick with current major version (meaning "non-breaking changes only") but pick highest available "stable" version.&lt;br&gt;
&lt;strong&gt;In fact there are no strict rules for the tags or versions.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  3.4. Npm version update
&lt;/h3&gt;

&lt;p&gt;You can use command &lt;code&gt;npm version&lt;/code&gt; to update your version.&lt;br&gt;
Example flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm version 0.0.1  # versions starting with 0 are often considered to be not yet completed
npm version major  # bumps to 1.0.0 (breaking change)
npm version minor  # bumps to 1.1.0 (new feature)
npm version patch  # bumps to 1.1.1 (bugfix)
npm version prerelease --preid next  # bumps to 1.1.2-next.0
npm version prerelease --preid next  # bumps to 1.1.2-next.1
npm version minor  # bumps to 1.2.0
npm version prerelease --preid next  # bumps to 1.2.1-next.0
npm version patch  # bumps to 1.2.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Command &lt;code&gt;npm version&lt;/code&gt; has a special logic when everuted from within a git repository - then a new commit with version update is created and a new annotated tag is created.&lt;/p&gt;

&lt;p&gt;Keeping version in the source code has pros and cons. Most important cons is probably that version must be known "in advance" while many might prefer to have a build result (an artifact) which is tested and given its number after tests are passed.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.5. Npm code scan
&lt;/h3&gt;

&lt;p&gt;Npm has built-in commands for code scan:&lt;br&gt;
&lt;code&gt;npm outdated&lt;/code&gt; shows any packages having newer versions (beware of packages like &lt;a href="https://www.npmjs.com/package/stack-trace/v/1.0.0-pre1"&gt;stack-trace&lt;/a&gt; which has non-standard pre-release published on latest tag).&lt;br&gt;
&lt;code&gt;npm audit&lt;/code&gt; scans your code for known vulnerabilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Code examples
&lt;/h2&gt;

&lt;p&gt;I might update the examples in the future&lt;/p&gt;

&lt;h3&gt;
  
  
  4.1. Async/Await example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function myMethod(){
  const result1 = readFileAsync('/filename');
  console.log('This gets immediately printed BEFORE file is read');
  console.log(result1); // Prints "Promise" and is not yet resolved
  const result2 = await readFileAsync('/filename');
  console.log('This is not executed until result2 promise gets fulfilled').
  console.log(result2); // Prints result as it was already read
}

myMethod(); // Here I can use promises but not async/await - but I could "run" the async method "in the background"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. IDE (Integrated Development Environment)
&lt;/h2&gt;

&lt;p&gt;Paid one &lt;a href="https://www.jetbrains.com/webstorm/"&gt;https://www.jetbrains.com/webstorm/&lt;/a&gt; (IntelliJ ultimate includes all its features).&lt;/p&gt;

&lt;p&gt;Free one and providing very similar experience: &lt;a href="https://code.visualstudio.com/"&gt;https://code.visualstudio.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are many other IDE's available (ex. &lt;a href="https://atom.io/"&gt;https://atom.io/&lt;/a&gt; which is written using node, javascript and npm).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Please let me know if you can find any issues with this post, do I can fix it.&lt;/strong&gt; Also if you would like any topic to be added in this or another post.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>npm</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Kafka vs RabbitMQ</title>
      <dc:creator>Maciej Wakuła</dc:creator>
      <pubDate>Sat, 29 Oct 2022 23:35:31 +0000</pubDate>
      <link>https://dev.to/adderek/kafka-vs-rabbitmq-4073</link>
      <guid>https://dev.to/adderek/kafka-vs-rabbitmq-4073</guid>
      <description>&lt;p&gt;This is a response to the article &lt;a href="https://dev.to/rakeshkr2/kafka-vs-rabbitmq-4ioj"&gt;an article with same name&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Both Kafka and RabbitMQ are used to relay messages between message producers and message consumers. RabbitMQ can handle large amount of messages (dozens up to thousands per second) but Kafka can handle much higher traffic. Unless you are working with very high volume of messages, the kafka would be an overkill.&lt;/p&gt;

&lt;h1&gt;
  
  
  Distribudion
&lt;/h1&gt;

&lt;p&gt;RabbitMQ (in "new" version 3.7 or newer) consists of "durable" instances (working and saving data) and "working instances" (not saving data). Works well with 1+ instances. Works with exchanges and queues.&lt;/p&gt;

&lt;p&gt;Kafka spreads all messages through the instances (works well with 3+ instances, preferably 5+). Can work with single instance (for development/test purpose). You must set "partitioning key" to guarantee that messages are processed in order (for this key). It is not a queue.&lt;/p&gt;

&lt;h1&gt;
  
  
  High availability
&lt;/h1&gt;

&lt;p&gt;RabbitMQ works well but you should not assume that it is 100% available. Under some rare circumstances messages could be lost.&lt;/p&gt;

&lt;p&gt;Kafka is using multiple servers and quorum. Much has changed between versions 1, 2 and 3. Internally Kafka 2 and 3 are fully transactional to ensure that no messages are lost. Its "exactly once delivery" ensures that a message is delivered at least once (to the library, not necessary processed) OR delivered at least once (be prepared for same messages delivered multiple times).&lt;br&gt;
Kafka is using either zookeeper or its own kraft protocol (available since kafka 2.80).&lt;/p&gt;

&lt;h1&gt;
  
  
  Performance
&lt;/h1&gt;

&lt;p&gt;Kafka can scale much - use it for REALLY high messages volume.&lt;/p&gt;

&lt;p&gt;RabbitMQ works well with high load but expect dead-end when dealing with HUGE load.&lt;/p&gt;

&lt;h1&gt;
  
  
  Replication
&lt;/h1&gt;

&lt;p&gt;In RabbitMQ messages gets copied, consumed or dequeued (when time to live reached). Or lost (worst nightmare as you have no idea what happened).&lt;/p&gt;

&lt;p&gt;In Kafka messages are stored for some time, never lost. Even if consumed  you can still access then to see what happened.&lt;br&gt;
You can replicate all the messages to secondary data center (and delay is not an issue).&lt;/p&gt;

&lt;h1&gt;
  
  
  Multi subscriber
&lt;/h1&gt;

&lt;p&gt;In RabbitMQ you must control who should receive the messages and handle when message is not consumed in time.&lt;/p&gt;

&lt;p&gt;Kafka is just a journal of messages. Same messages can be consumed by many consumer groups and you can always re-consume them (unless timed out).&lt;/p&gt;

&lt;h1&gt;
  
  
  Message Protocols
&lt;/h1&gt;

&lt;p&gt;RabbitMQ is a "Standard" in terms of protocol but it is quite complex (and examples and libraries are not easy to understand). If you dig into the libs then all are just barely proof-of-concept's.&lt;/p&gt;

&lt;p&gt;With enterprise level kafka is easier to feel but you must feel also asynchronous message processing. Rabbit works well for synchronous one.&lt;/p&gt;

&lt;h1&gt;
  
  
  Message Ordering
&lt;/h1&gt;

&lt;p&gt;RabbitMQ if an advanced queue. Message ordering is "guaranteed" (but messages not processed are re-queued what means they could get to the end of queue).&lt;/p&gt;

&lt;p&gt;Kafka is NOT an queue but you can use partitioning key to ensure those are processed in order. Expect issues when your consumer is not responding and same messages are passed to another consumer. Expect issues when single partitioning keys contians VERY HIGH amount of messages (it could block an partition).&lt;/p&gt;

&lt;h1&gt;
  
  
  Message lifetime
&lt;/h1&gt;

&lt;p&gt;In RabbitMQ message consumed is gone.&lt;/p&gt;

&lt;p&gt;In Kafka message stays until removed.&lt;/p&gt;

&lt;h1&gt;
  
  
  Architecture
&lt;/h1&gt;

&lt;p&gt;RabbitMQ is handling message delivery and logic "what to do if delivery fails". This pushes responsibility to the message producer (sender). Your service must handle multiple delivery failure scenarios.&lt;/p&gt;

&lt;p&gt;Kafka is rather "fire ans forget". You produce a message and don't care if it is consumed by anyone. This helps is decoupling of services. You must handle problems in consumers so producers are more simple.&lt;/p&gt;

&lt;h1&gt;
  
  
  Use Cases
&lt;/h1&gt;

&lt;p&gt;Kafka is meant for asynchronous message delivery (fire and forget).&lt;/p&gt;

&lt;p&gt;RabbitMQ is a message send and handle delivery failures. You have better control over the delivery but you must handle all the scenarios.&lt;/p&gt;

&lt;h1&gt;
  
  
  Transactions
&lt;/h1&gt;

&lt;p&gt;Kafka has transactions. RabbitMQ does not. If you want reliable transactions then more complex kafka can provide this.&lt;/p&gt;

&lt;h1&gt;
  
  
  Language
&lt;/h1&gt;

&lt;p&gt;RabbitMQ is written in Erlang (older versions are using erlang config files).&lt;br&gt;
Kafka is written in scala (based on java).&lt;/p&gt;

&lt;h1&gt;
  
  
  Routing Support
&lt;/h1&gt;

&lt;p&gt;Both options are OK but handle your routing differently (kafka pushes it to the consumers while rabbit depends much on the producer)...&lt;/p&gt;

&lt;h1&gt;
  
  
  Developer Experience
&lt;/h1&gt;

&lt;p&gt;Rabbit seems simple at first glance but fails when issues appear.&lt;/p&gt;

&lt;p&gt;Kafka is much more challenging at first but then does not fail once you understand how it works. Ir requires much more knowledge and experience.&lt;/p&gt;

&lt;p&gt;Kafka can be scaled to much higher volume.&lt;br&gt;
Kafka requires more knowledge.&lt;br&gt;
Kafka provides better disaster recovery.&lt;/p&gt;

&lt;h1&gt;
  
  
  Disk space
&lt;/h1&gt;

&lt;p&gt;I decided to add this one extra as it is important but not straightforward to notice or understand.&lt;br&gt;
&lt;strong&gt;Kafka keeps messages for a while, message is kept only once but can be consumed multiple times.&lt;/strong&gt; It consumes much disk space because you keep them for a while just in case a consumer is not available for a while. Messages should be small (preferably kilobytes). Consumer outage is not that scary anymore. You often want to outsource Kafka management to a company focused on that (having know-how and well established tools).&lt;br&gt;
&lt;strong&gt;RabbitMQ can handle larger messages but copies them for every subscriber. Once consumed, the message is gone.&lt;/strong&gt; As a result only few messages are kept and you need less disk space. If message is not consumed in time, it gets to a dead letter queue. Consumer outage is a pain and often forces someone to handle it manually. Your nightmare is a message that gets consumed but not processed as you end up digging the logs. System management is often very bound to domain knowledge so outsourcing might be difficult.&lt;/p&gt;

&lt;h1&gt;
  
  
  How this document was created
&lt;/h1&gt;

&lt;p&gt;It was created in relation to the &lt;a href="https://dev.to/rakeshkr2/kafka-vs-rabbitmq-4ioj"&gt;https://dev.to/rakeshkr2/kafka-vs-rabbitmq-4ioj&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>rabbitmq</category>
    </item>
  </channel>
</rss>
