<?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 Nicola Del Gobbo on Medium]]></title>
        <description><![CDATA[Stories by Nicola Del Gobbo on Medium]]></description>
        <link>https://medium.com/@nicknaso?source=rss-a00134ce20e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Z3JAAil3ZPw3nPL8.jpeg</url>
            <title>Stories by Nicola Del Gobbo on Medium</title>
            <link>https://medium.com/@nicknaso?source=rss-a00134ce20e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 16:45:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nicknaso/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[Porting five real Node-API (N-API) addons from node-gyp and CMake to Marmotta]]></title>
            <link>https://medium.com/@nicknaso/porting-five-real-node-api-n-api-addons-from-node-gyp-and-cmake-to-marmotta-515a7cc773e5?source=rss-a00134ce20e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/515a7cc773e5</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[zig]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[build-tool]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nicola Del Gobbo]]></dc:creator>
            <pubDate>Thu, 08 Oct 2026 01:55:51 GMT</pubDate>
            <atom:updated>2026-10-08T01:55:51.086Z</atom:updated>
            <content:encoded><![CDATA[<p>One CI runner, every target, no Python or Visual Studio. Here is what broke along the way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v4fcAgkVuHTvlnd20KmNUg.jpeg" /><figcaption>Marmotta — a Node.js native addon build tool</figcaption></figure><h3>The problem: the build, not the API</h3><p>Node-API solved ABI stability in 2017. One .node binary built against N-API version 8 loads on every Node.js release that supports it, so there is no more rebuilding for each major version.</p><p>The build itself did not get easier. Shipping a native addon today still means:</p><ul><li><strong>A host toolchain per OS.</strong> node-gyp needs Python, make and GCC/Clang on Linux, Xcode on macOS, and Visual Studio on Windows. CMake.js swaps Python for CMake but still needs the native compiler.</li><li><strong>A CI runner per target.</strong> Neither tool cross-compiles in practice, so every platform/arch/libc combination gets its own job: a macOS runner, a Windows runner, an Alpine container for musl, QEMU for armv7, a FreeBSD VM.</li><li><strong>A second tool for distribution.</strong> prebuildify, prebuild or node-pre-gyp package the binaries, and node-gyp-build finds them at runtime.</li></ul><p>The consequence is that CI for a 200-line C binding is often longer than the binding. In node-argon2, the release workflow alone ran 10 build jobs across native runners, QEMU containers and a FreeBSD VM to produce 12 prebuilt binaries.</p><h3>What Marmotta is</h3><p><a href="https://github.com/napi-bindings/marmotta">Marmotta</a> is a TypeScript CLI that compiles C/C++ Node-API addons with the Zig toolchain (zig cc / zig c++). Zig bundles Clang plus libc headers and sysroots for dozens of targets, so one host can emit binaries for Linux glibc/musl, macOS and Windows.</p><p>A marmotta build does four things:</p><ol><li><strong>Resolves the toolchain.</strong> It uses zig from PATH, otherwise downloads the latest stable release into ~/.marmotta (x64/ARM64 hosts on Linux, macOS, Windows).</li><li><strong>Loads the config.</strong> marmotta.config.json, or marmotta.config.js exporting a function that receives { target, platform, arch }.</li><li><strong>Supplies the Node-API headers</strong> from the node-api-headers npm package. On Windows it also generates the node_api import library, so no node.lib download is needed.</li><li><strong>Compiles and links</strong> every source with separate C and C++ flags, then writes &lt;name&gt;.node.</li></ol><p>The CLI mirrors node-gyp and CMake.js: configure, build, rebuild, clean, plus install, list and remove &lt;version&gt; to manage Zig versions. Cross-compilation is one flag: --target aarch64-linux-musl.</p><p>The smallest useful config is five lines (this is bufferutil’s, in full):</p><pre>{<br>  &quot;name&quot;: &quot;bufferutil&quot;,<br>  &quot;sources&quot;: [&quot;src/bufferutil.c&quot;],<br>  &quot;outputDir&quot;: &quot;build&quot;<br>}</pre><p>When a project needs conditionals, the JS form replaces gyp’s conditions with plain code. This excerpt is from node-argon2:</p><pre>module.exports = ({ target, platform, arch }) =&gt; {<br>  const triple = target ?? &quot;&quot;;<br>  // With --target, decide from the Zig triple; otherwise from the host<br>  const isX86 = target<br>    ? /^(x86_64|i[3-6]86)-/.test(triple)<br>    : arch === &quot;x64&quot; || arch === &quot;ia32&quot;;</pre><pre>  return {<br>    name: &quot;argon2&quot;,<br>    sources: [&quot;argon2.cpp&quot;, /* ... */ `argon2/src/${isX86 ? &quot;opt.c&quot; : &quot;ref.c&quot;}`],<br>    cFlags: [...defines, ...(isX86 ? [&quot;-msse&quot;, &quot;-msse2&quot;] : [])],<br>    // ...<br>  };<br>};</pre><h3>Marmotta vs. the Node-API build tools</h3><p>Marmotta competes with the two compiler drivers, node-gyp and CMake.js, not with the three packaging tools. The <a href="https://github.com/nodejs/abi-stable-node/blob/doc/node-api-build-tools.md">Node-API build tools list</a> splits them the same way.</p><ul><li><strong>Marmotta</strong> (compile). Needs Node.js 20+ and tar; Zig is downloaded for you. Cross-compiles from any host with --target &lt;zig-triple&gt;. Config is JSON or a JS function. No prebuild packaging: you write to prebuilds/ with -o.</li><li><a href="https://github.com/nodejs/node-gyp"><strong>node-gyp</strong></a> (compile). Needs Python, make, GCC/Clang, Xcode or Visual Studio. No cross-compilation in practice. Config is binding.gyp with gyp conditions. Prebuilds via prebuildify or node-pre-gyp.</li><li><a href="https://github.com/cmake-js/cmake-js"><strong>CMake.js</strong></a> (compile). Needs CMake plus a native compiler. Cross-compiles only with hand-written toolchain files. Config is CMakeLists.txt. Prebuilds via prebuild.</li><li><a href="https://github.com/mapbox/node-pre-gyp"><strong>node-pre-gyp</strong></a> (package + download). Same toolchain as node-gyp. Uploads binaries to S3 or any server.</li><li><a href="https://github.com/prebuild/prebuild"><strong>prebuild</strong></a> (package + download). Works on top of node-gyp or CMake.js. Uploads to GitHub Releases only.</li><li><a href="https://github.com/prebuild/prebuildify"><strong>prebuildify</strong></a> (package). Works on top of node-gyp. Bundles binaries inside the npm tarball.</li></ul><h3>Where Marmotta wins</h3><ul><li><strong>One host, every target.</strong> Linux glibc (with a pinned glibc version such as .2.17), musl, macOS and Windows binaries come out of a single ubuntu job.</li><li><strong>Zero system prerequisites.</strong> No Python, no Visual Studio, no build-base. The compiler is a self-contained download.</li><li><strong>Config is code.</strong> Platform branches are if statements, not nested gyp dictionaries or CMake generator expressions.</li><li><strong>Same compiler everywhere.</strong> Clang via Zig on every target, so flags and warnings behave identically on Windows and Linux.</li></ul><h3>Where it loses today</h3><ul><li><strong>No packaging layer.</strong> There is no node-gyp-build equivalent, so each project writes its own loader and install hook (see below).</li><li><strong>C and C++ only.</strong> No assembly (.S) sources, which matters for crypto libraries.</li><li><strong>No dependency graph.</strong> One target, one source list: no static-library sub-targets, no fetch_package, no node-addon-api integration.</li><li><strong>Young.</strong> Version 0.5, a small user base, and Zig itself is pre-1.0, so a new stable release can change behaviour.</li></ul><h3>Five real ports</h3><p>To test Marmotta against code that ships to millions of installs, five popular addons were ported from their existing toolchain: <a href="https://github.com/sodium-friends/sodium-native">sodium-native</a>, <a href="https://github.com/ranisalt/node-argon2">node-argon2</a>, <a href="https://github.com/kelektiv/node.bcrypt.js">node.bcrypt.js</a>, <a href="https://github.com/lovell/farmhash">farmhash</a> and <a href="https://github.com/websockets/bufferutil">bufferutil</a>.</p><p>Diff sizes per repo (lines added / removed, excluding package-lock.json):</p><pre>Addon           Config     Repo diff     CI workflows<br>--------------  ---------  ------------  ------------<br>sodium-native   JS, 228    +17 / -331    +11 / -44<br>node-argon2     JS, 52     +57 / -347     +6 / -183<br>node.bcrypt.js  JSON, 20  +115 / -127    +52 / -20<br>farmhash        JSON, 13   +31 / -49     +20 / -41<br>bufferutil      JSON, 5    +26 / -28        n/a</pre><p>The pattern is consistent. Simple addons (bufferutil, farmhash, bcrypt) map to a static JSON file. Addons with vendored libraries and per-platform logic (argon2, sodium-native) need the JS config, and that is where the effort goes.</p><p>What changed in each, in one line:</p><ul><li><strong>sodium-native</strong> (libsodium in C and ASM, C++ binding; was CMake + bare-make): a 228-line JS config replaces CMakeLists.txt and four CMake helper packages. It clones libsodium at a pinned commit and rebuilds the HAVE_* define matrix per OS and arch. See: <a href="https://github.com/NickNaso/sodium-native/tree/feat/marmotta-build-tool">https://github.com/NickNaso/sodium-native/tree/feat/marmotta-build-tool</a></li><li><strong>node-argon2</strong> (argon2 in C, C++ binding; was node-gyp + prebuildify): the release workflow went from 10 jobs (native runners, QEMU, FreeBSD VM) to one Ubuntu job looping over 12 Zig triples, including x86_64-linux-gnu.2.17 and aarch64-freebsd. See: <a href="https://github.com/NickNaso/node-argon2/tree/feat/marmotta-build-tool">https://github.com/NickNaso/node-argon2/tree/feat/marmotta-build-tool</a></li><li><strong>node.bcrypt.js</strong> (C++ with node-addon-api; was node-gyp + prebuildify in Docker): six Docker-based prebuildify invocations became a while read loop of marmotta build --target … --out …. The install hook was dropped. See: <a href="https://github.com/NickNaso/node.bcrypt.js/tree/feat/marmotta-build-tool">https://github.com/NickNaso/node.bcrypt.js/tree/feat/marmotta-build-tool</a></li><li><strong>farmhash</strong> (C++ with node-addon-api; was node-gyp): CI dropped Python, gcc-toolset-14 and build-base. A 6-line script renames the output to the platform-suffixed name the loader expects. See: <a href="https://github.com/NickNaso/farmhash/tree/feat/marmotta-build-tool">https://github.com/NickNaso/farmhash/tree/feat/marmotta-build-tool</a></li><li><strong>bufferutil</strong> (C; was node-gyp + prebuildify): node-gyp-build was replaced by a 15-line loader that tries prebuilds/&lt;platform&gt;-&lt;arch&gt;/ then build/, keeping the pure-JS fallback. See: <a href="https://github.com/NickNaso/bufferutil/tree/feat/marmotta-build-tool">https://github.com/NickNaso/bufferutil/tree/feat/marmotta-build-tool</a></li></ul><h3>What made the porting hard</h3><p>Compiling was never the hard part. The friction sits in everything node-gyp and CMake did implicitly, which now has to be written down.</p><h3>1. No runtime loader</h3><p><em>Seen in: all five.</em> With node-gyp-build gone, each project wrote its own: look in prebuilds/&lt;platform&gt;-&lt;arch&gt;[-musl]/, then build/, detecting musl via process.report. The result is five slightly different loaders, and bcrypt dropped its install hook, so unsupported platforms now throw instead of building from source.</p><h3>2. Assembly sources unsupported</h3><p><em>Seen in: sodium-native.</em> libsodium’s .S files were excluded and the portable C implementations used instead. Expect slower x64 crypto primitives (the HAVE_AMD64_ASM path is gone); this is not benchmarked yet.</p><h3>3. Headers beyond Node-API</h3><p><em>Seen in: sodium-native.</em> The binding also needs uv.h and node_version.h, so the config downloads the full Node headers, plus node.lib on Windows. That means network access at config time and headers tied to the Node version doing the build.</p><h3>4. No sub-targets or dependency fetching</h3><p><em>Seen in: argon2, sodium-native.</em> Static-library targets were flattened into one source list, and libsodium is cloned at a pinned commit from inside the config. Side effects now live in a config file, and sodium-native maintains 228 lines in place of CMake.</p><h3>5. gyp conditions and arch-specific sources</h3><p><em>Seen in: argon2, farmhash.</em> Rewritten as JS branches on the Zig triple (opt.c vs ref.c, -msse2 on x86 only). The logic has to handle both --target and host detection.</p><h3>6. node-addon-api integration</h3><p><em>Seen in: bcrypt, farmhash, argon2.</em> The include path is added by hand, and bcrypt needed #define NODE_GYP_MODULE_NAME, which node-gyp used to inject silently. The JSON configs hardcode node_modules/node-addon-api, which breaks under hoisting; the JS form, require(&quot;node-addon-api&quot;).include_dir, is safer.</p><h3>7. MSVC and Xcode settings with no Clang equivalent</h3><p><em>Seen in: farmhash, bufferutil, argon2, bcrypt.</em> Dropped: /Brepro reproducible builds, MACOSX_DEPLOYMENT_TARGET 10.7, -Os, strip and dead-strip flags, and Windows-only defines. Expect larger binaries, and the minimum macOS version is now Zig&#39;s default.</p><h3>8. Platforms outside Zig’s targets or Marmotta’s scope</h3><p><em>Seen in: sodium-native, bcrypt, argon2.</em> Android, iOS and the Bare runtime were removed from sodium-native, z/OS from bcrypt, and the FreeBSD tests and _FORTIFY_SOURCE matrix from argon2. These are coverage regressions that need an explicit decision from maintainers.</p><p>Two lessons stand out. First, the hidden contract of node-gyp is larger than binding.gyp: module-name macros, exception flags from node-addon-api, and the loader all came for free. Second, a JS config is the right escape hatch, but it moves build logic into the least-reviewed file of the repo.</p><h3>What the ports gained</h3><p>The biggest win is in CI and in the contributor setup, not in the C/C++ code, which was untouched except for one macro in bcrypt.</p><ul><li><strong>CI collapses to one runner.</strong> node-argon2’s release went from 10 jobs on four kinds of infrastructure to one ubuntu-22.04 job producing 12 binaries, including FreeBSD x64/arm64 without a VM. Its two workflows lost 183 lines and gained 6.</li><li><strong>glibc pinning without old distros.</strong> Triples like x86_64-linux-gnu.2.17 target an old glibc directly. Previously that guarantee came from building inside rockylinux:8 or almalinux-devtoolset11 images.</li><li><strong>No system toolchain.</strong> Python, make, gcc-toolset-14, build-base, LLVM from Chocolatey and Visual Studio disappeared from every workflow.</li><li><strong>Fewer dependencies.</strong> Across the five repos the ports removed node-gyp, prebuildify, node-gyp-build, cross-env, cmake-bare, cmake-fetch, cmake-napi and the global bare-make, replacing them with one package.</li><li><strong>Readable platform logic.</strong> A cFlags.push(...) inside if (os === &quot;linux&quot;) is easier to review than a gyp target_conditions nested under configurations.Release.</li></ul><p>node-argon2’s README now says it in one line:</p><blockquote>You do not need Python, make, GCC or Visual Studio.</blockquote><p>Not measured yet: build time, binary size and runtime performance against the original artifacts. Those are the numbers that decide whether maintainers would accept these ports upstream.</p><h3>Trade-offs and next steps</h3><p>Marmotta makes the compiler a dependency you download, not a machine you provision. For pure C/C++ addons with no assembly, that trade is already worth it: bufferutil, farmhash and bcrypt ported with a JSON file and a handful of script lines.</p><p>For addons with heavy native dependencies, the cost moves into the config. sodium-native works, but at the price of dropped assembly, three dropped platforms and a 228-line config that does network I/O.</p><p>The ports point to a short roadmap:</p><ol><li><strong>A shared loader.</strong> A marmotta/load helper (prebuilds lookup, musl detection, source-build fallback) would delete five hand-written loaders.</li><li><strong>Assembly and static-library targets.</strong> Zig already assembles .S files, so exposing them in the config would restore libsodium&#39;s fast paths.</li><li><strong>node-addon-api awareness.</strong> Resolve its include dir and define NODE_GYP_MODULE_NAME automatically.</li><li><strong>Pinned Zig versions</strong> in the config, so a new Zig stable release cannot change a published binary.</li><li><strong>Benchmarks</strong> of build time, binary size and throughput against the original node-gyp/CMake artifacts.</li></ol><p>The project is on GitHub at <a href="https://github.com/napi-bindings/marmotta">napi-bindings/marmotta</a> and on npm as marmotta. If you maintain a native addon, try npx marmotta buildon it and open an issue with what broke. PRs are welcome 🎉</p><p><a href="https://github.com/napi-bindings/marmotta">GitHub - napi-bindings/marmotta: Marmotta - a Node.js native addon build tool</a></p><h3>Acknowledgements</h3><p>Thank you to all people that encourage me every day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=515a7cc773e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some notes about: Monolith vs Microservices]]></title>
            <link>https://medium.com/@nicknaso/some-notes-about-monolith-vs-microservices-30706b6d2335?source=rss-a00134ce20e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/30706b6d2335</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Nicola Del Gobbo]]></dc:creator>
            <pubDate>Tue, 08 Sep 2020 09:37:21 GMT</pubDate>
            <atom:updated>2020-09-08T09:43:23.494Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*bQ4sfKYfmcZ3LRHdouGQ0w.png" /><figcaption>Monolith vs Microservices</figcaption></figure><p>Software development is an art. It isn’t predictable enough to be engineering. It isn’t rigorous enough to be science. Developers are artis and that is not a good thing.</p><p><strong>One of the biggest problem today is that we can’t write software faster enough</strong>. We can’t write software that meets business and that is sufficiently accurate and reliable.</p><p>When the requirements change in the middle of a project it damages the architecture so badly that we spiral into a death march of hacks and kludges our data structure, concepts, entity relationships into a compliance.</p><p>Requirements are always underspecified. Bad management wastes time and eats up development schedules. Our non technical colleagues have complex challenges of their own, it’s time to grow up and accept that we have a problem: <strong>we can’t write software fast enough</strong>.</p><p>There is a difference between technical infrastructure and the business logic. One of the key roles is to make the big things out of the small things.</p><p>Microservices create too much overhead at the start of a project. The business logic implementing a microservices con have multiple runtime configurations, meaning it can partecipate in the system in many ways, without requiring changes in the business logic code.</p><p>With microservice approach you can follow the <strong>principle of additivity</strong>, your only action is to add new microservices, leaving the others running.</p><p>There is no downtime, and the risk of breakage is low. In case you want to experiment a new version of micorservice you could deploy and start a new instance of it keeping the old one. In this way you can have multiple version of a service deployed in production.</p><p>This is very far by the updating the entire system and there are no unforeseen effects in production. The big advantage of using microservices architecture is its own <strong>composability</strong>.</p><p>Adding a new feature does not consist of extending an existing service, but you will add a new microservice. This avoid technical debt by moving complexity into message routing configuration and out of conditional code.</p><p>You have to understand the system by organising the message patterns into a hierarchy, which is mush easier to comprehend them an object relationship graph.</p><p>In a traditional system you end up putting most of your data in one big central database because that is the path of least resistance at the code level. In microservices would you are freed from this constraints.</p><p>The microservices are not affected by each others choice of data store and this makes cadges easier. If you find the need to migrate to a different database then the impact of the change will be minimised.</p><p>In a monolith you have too many ways to interact with other objects. Every developer has access to the entire code base and can create dependencies faster and when it’s clear that encapsulation is suffering there is often no time for refactoring. <strong>This is a recipe to increase the technical debt</strong>.</p><p>If you use complexity as a proxy measure of technical debt you can see that object oriented monolith are more vulnerable to technical debt. <strong>The measure is given to you by the total of possible interaction between the elements</strong>.</p><p>The prefix micro indicates that <strong>the components are small avoiding accumulation of technical debt</strong>.</p><p>Composition works well only when the means of communication between the components is uniform. It’d not the mechanism for the communication that matters, but its simplicity.</p><p><strong>Microservices in practice are small, because the smaller a service is, the easier is to compose. And if it’s small its implementation language matters less</strong>.</p><p>A service may be disposable, because rewriting it’d functionality does not require much work.</p><p><strong>The power of additivity helps to contain the technical debt, the changing of business requirements can be met by adding a new microservices not modifying or breaking the old ones</strong>.</p><p>You need some automations to control the large network of the services. This immunise you against human errors. Move from the general to the specific you should solve the simplest general problem first and then the special cases. Following this approach preserves the additivity and keep the technical debt lower.</p><p>The system management is too complicated and needs automation. Unlike with the monolith, where scaling is all or nothing you can easily have variable numbers of different microservices running and applying scaling only when needed.</p><p>There is no excuse for not doing this and it is not a criticism of the microservices architecture to say that it’s difficult to achieve. This is a baseline feature of any reasonable deployment tool or cloud platform.</p><p>The monitoring of microservice system is different from the monolith, because the used measurements of low level health such as CPU and memory usage are far less significant. From a system perspective what matters is the flow of messages.</p><p>Additivity allows the microservices architecture to clean itself.</p><p>The microservice attitude is the belief that it helps to deliver fast and to create a business value with the software in a practical and efficient way.</p><p>Sometimes we believe that microservices are mini web server offering a small REST based api that accepts and returns JSON documents. This is a limited view on what microservice really is.</p><p>A microservice is an independent software component that takes no more the one iteration to build and deploy.</p><p>When there are a few services you can configure each services with the network locations of the other services, but this practice becomes unmanageable as the numbers of the service grows. The standard solution is to use a <strong>service discovery mechanism </strong>(etcd, Consul, Zookeeper, …).</p><p>You could have a policy to scale a group of microservices or a single one and to do that you need a <strong>load balancer </strong>(NGINX, HAProxy, Eureka, Envoy, …).</p><p>You should avoid the <strong>distributed monolith </strong>this happen one service is starting to strictly depend on other. This condition go under the name of “The trap of the distributed monolith”.</p><p>In microservices environment you can safely violate the DRY (Don’t Repeat Yourself) principle, because very often the general case is not sufficient to handle the complexity of a specific case. This will contribute to keep every service isolated from each other.</p><p>In a monolith you have one code base a single developer could break the build then all others will be blocked. In the monolith the technical debt increase rapidly. A well structured design is too weak to resist the immediate needs of an entire team working against the clock to deliver a feature.</p><p>The deployment risk associated with a monolith causes slow, infrequent releases of new features. You can only mitigate the problems arisen by the monolith, but in reality there is not project management technique that can overcome the engineering deficits of the monolith architecture.</p><p><strong>You can reserve different effort for different service. Not all services are mission critical and need to follow the same quality rules</strong>.</p><p><strong>The power of the microservices architecture comes from the fact that it offers a unified solution to many different scaling problems</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30706b6d2335" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debug Node.js native addon with Xcode]]></title>
            <link>https://medium.com/@nicknaso/debug-node-js-native-addon-with-xcode-656d740003c0?source=rss-a00134ce20e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/656d740003c0</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[addons]]></category>
            <category><![CDATA[clang]]></category>
            <category><![CDATA[cpp]]></category>
            <dc:creator><![CDATA[Nicola Del Gobbo]]></dc:creator>
            <pubDate>Wed, 04 Mar 2020 13:35:20 GMT</pubDate>
            <atom:updated>2020-03-04T13:41:24.534Z</atom:updated>
            <content:encoded><![CDATA[<p>While I was working on a native addon for Node.js I had the need to debug my native code. In this article I want to share my experience on how to execute the debug through Xcode.</p><p>What many developers don’t know is that you can use <a href="https://github.com/nodejs/node-gyp"><strong>node-gyp</strong></a><strong> </strong>to create an Xcode project. This is possible following few steps:</p><ul><li>Go inside the folder of your project</li><li>Execute the following command:</li></ul><pre>node-gyp build &amp;&amp;<br>node-gyp configure --debug -- -f xcode</pre><p>At the end of the execution of the previous command a new folder called <strong>build</strong> has been generated on your project and inside it you can find two new files:</p><ul><li><strong>binding.xcodeproj</strong></li><li><strong>config.gypi</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*IW-XB29tesN0JZ8m06ctdQ.png" /><figcaption>Content of build folder</figcaption></figure><p>Now you can open the file <strong>binding.xcodeproj </strong>through Xcode and use this IDE to <strong>edit</strong>, <strong>debug </strong>and<strong> build </strong>your native addon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MU9Fmz2dBYZecqi1kWlhXw.png" /></figure><p>Edit and build your code is a simple task you only have to select the source file change it and then press the button <strong>Build and run …</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*21yRMBf1ktyKnECB0pQ5WQ.png" /></figure><p>Now it’s time to configure the <strong>debug and </strong>like first thing you need to select<strong> </strong>the project<strong> addon </strong>and then<strong> Edit Scheme …</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8zoLq5dqyX0sID7mQyq7SQ.png" /></figure><p>In the tab <strong>info</strong> set the executable that Xcode will use when you want to execute the debug operation. In this case you have to set the executable to the path of your <strong>Node.js</strong> installation that you can retrieve with the following command:</p><pre>which node</pre><p>The result of the command should be something like this:</p><pre>/usr/local/bin/node</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1i6W8_DzbCmnRw5LwVXZSQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qKyXWobCB_QDAmuBkmcWEg.png" /></figure><p>In the tab <strong>arguments </strong>you have to set the script that you want to start on executing the debug. In my case it is the <strong>index.js </strong>file placed in the root folder of my project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ir4uC7yTkrsECNsMMb99Xg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ecSVy-MDOWCjwmDd5VEdkg.png" /></figure><p>Finally it’s all set and you can start using Xcode to debug your native code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RiyeBqauc9SeHDqRJGXPQA.png" /><figcaption>Use Xcode debug</figcaption></figure><p>In this article I used very simple code example that you can find here:</p><p><a href="https://github.com/NickNaso/debug-addon-xcode">NickNaso/debug-addon-xcode</a></p><h3>Acknowledgements</h3><p>Thank you to all people that encourage me every day.</p><p><a href="https://medium.com/u/a00134ce20e1">Nicola Del Gobbo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=656d740003c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[noUiSlider]]></title>
            <link>https://medium.com/@nicknaso/nouislider-9d1ad04f6a0a?source=rss-a00134ce20e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d1ad04f6a0a</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Nicola Del Gobbo]]></dc:creator>
            <pubDate>Thu, 02 Aug 2018 19:26:51 GMT</pubDate>
            <atom:updated>2018-08-02T19:26:51.435Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi everyone in this article I want just share my notes about <a href="https://refreshless.com/nouislider/"><strong><em>noUiSlider</em></strong></a> that is a JavaScript range slider. In these days I used this beautiful library to built a component that allow me to handle the choice of credits on a subscription system.</p><p>This is my final result and I want thank to my colleague <a href="https://twitter.com/pierluigiiannar">Pierluigi Iannarelli </a>to suggest me this wonderful JavaScript module.</p><p>Here my final results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y1d9yB_T5qSGwSz1zfZKlQ.png" /></figure><p>Here my notes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AVEXQ2wfu-O7aspuPff5Vg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6n0HzwVTvSl9TDKS0BFsWg.jpeg" /></figure><p>Useful resources about <strong>noUiSlider</strong>:</p><p><a href="https://refreshless.com/nouislider/"><strong><em>Documentation</em></strong></a></p><p><a href="https://github.com/leongersen/noUiSlider/"><strong><em>Source code</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d1ad04f6a0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Native Add-Ons and Event Emitter]]></title>
            <link>https://medium.com/@nicknaso/native-add-ons-and-event-emitter-ea66f09eb19c?source=rss-a00134ce20e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea66f09eb19c</guid>
            <category><![CDATA[events]]></category>
            <category><![CDATA[addons]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nicola Del Gobbo]]></dc:creator>
            <pubDate>Fri, 25 May 2018 20:13:44 GMT</pubDate>
            <atom:updated>2018-05-25T20:13:44.864Z</atom:updated>
            <content:encoded><![CDATA[<p>Node.js includes an <a href="https://nodejs.org/dist/latest/docs/api/events.html">event system</a> which is an implementation of the <strong>Observer</strong> pattern that is the most common used <strong>event</strong> pattern in Node.js application and for a good reasons:<strong><em> it’s incredibly simple and useful</em></strong>.</p><p>Anyone who has used Node.js should be familiar with <a href="https://nodejs.org/dist/latest/docs/api/events.htm">events</a>. This module has the responsibility to facilitate the communication between <strong>objects </strong>of your application.</p><blockquote>Much of the Node.js core API modules are built around an idiomatic asynchronous event-driven architecture in which some kinds of objects (called <strong>emitter</strong>) periodically emit named events that cause Function objects (“<strong>listeners</strong>”) to be called.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFzVNydvSRhSo1JsOyppag.png" /><figcaption>How event emitter works</figcaption></figure><p>Sometimes you need to promote loose coupling system by ensuring that instead of components (modules) referring to each other explicitly, their interaction is handled through an exchange of message using the <strong>events</strong>. <br>This can help to decouple the systems and improve the module reuse.</p><p>Let’s start off with a simple example to illustrate how an instance of the <strong>EventEmitter</strong> class can be created and used to listen to and trigger events.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11e38c1a15d9c54658c725f88f04b537/href">https://medium.com/media/11e38c1a15d9c54658c725f88f04b537/href</a></iframe><p>By default, all listeners attached to a particular event object are called by the <strong>EventListener </strong>object synchronously in the order in which they are registered or attached to the event object.</p><p><strong>How can emit an event from a native function?</strong></p><p>Usually a native add-on is composed by two parts one written in JavaScript and another written in C / C++. In most common cases the JavaScript part will use the functionality exposed by the native function to do something.</p><p>If you want emit an event from a native add-on the basic idea is to use the <strong>EventEmitter</strong> interface provided by Node.js core API. Specifically as reported in the code below it possible bind and pass the <strong>emit</strong> function to a function exposed by a native add-on.</p><p>What we expect in the code is that when the <strong>emit</strong> function will be called inside the native function it emits some events and then the corresponding listener will be executed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca03ea791f85a379675331c039a6861f/href">https://medium.com/media/ca03ea791f85a379675331c039a6861f/href</a></iframe><p>Launch an event from the native function now is very simple because we only need to call the <strong>emit</strong> function like reported in the code below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccb0b95a6238ec85df6ff627c872a150/href">https://medium.com/media/ccb0b95a6238ec85df6ff627c872a150/href</a></iframe><p>Every time we want trigger an event we have to call the emit function with the right parameters, but sometimes we want that our native object inherits all the behaviours of the <strong>EventEmitter </strong>and<strong> t</strong>o achieve at this purpose we can use the <strong>inherits</strong> function like reported in the code below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e373d5686e04b79fd5440b8d1a37db95/href">https://medium.com/media/e373d5686e04b79fd5440b8d1a37db95/href</a></iframe><p>Now the native object has all the fields and methods of <strong>EventEmitter</strong> and we can use them inside the C++ code.</p><p>In the following example we are creating a class that in its instance method emit some events.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59f48a7f98158d2f9a92cea9f52751a2/href">https://medium.com/media/59f48a7f98158d2f9a92cea9f52751a2/href</a></iframe><p>In this short article I wanted to illustrate how to use the <strong>EventEmitter</strong> interface provided by Node.js core API in the native add-ons and hope that it could be useful to someone.</p><p>In the examples that I proposed I triggered events from a native function that is executed <strong>synchronously</strong> on the <strong>event loop </strong>thread, but it could be more interesting emit an event from a native asynchronous function. I will update this article when all these other example will be ready.</p><p>All the code illustrated in this article is hosted in the following repository</p><p><a href="https://github.com/NickNaso/addon-event-emitter">NickNaso/addon-event-emitter</a></p><p>With my great joy these examples have been included in the official examples for <a href="https://github.com/nodejs/node-addon-api/"><strong>Node Addon API</strong></a><strong> </strong>and you can find them in the following repository, too:</p><p><a href="https://github.com/nodejs/abi-stable-node-addon-examples">nodejs/abi-stable-node-addon-examples</a></p><p>For most of you that want start to write their Node.js native addons using N-API I just repost some useful resources that was very useful to me:</p><p><a href="https://nodejs.org/dist/latest/docs/api/addons.html"><strong>C++ Addons</strong></a></p><p><a href="https://nodejs.org/dist/latest/docs/api/n-api.html"><strong>C++ Addons N-API</strong></a></p><p><a href="https://github.com/nodejs/node-addon-api"><strong>Node Addon API</strong></a></p><p><a href="https://youtu.be/-Oniup60Afs"><strong>N-API the next API for Native Addons</strong></a></p><p><a href="https://medium.com/the-node-js-collection/how-i-ported-bcrypt-to-new-n-api-d0b8c9fe6136"><strong>How I ported bcrypt to new N-API</strong></a></p><p><a href="https://medium.com/the-node-js-collection/speed-up-your-node-js-app-with-native-addons-5e76a06f4a40"><strong>Speed up Your Node.js App with Native Addons</strong></a></p><h3><strong>Acknowledgements</strong></h3><p>Thank you to all people that encourage me every day.</p><p>Thank you <a href="https://twitter.com/pierluigiiannar"><strong>Pierluigi Iannarelli</strong></a><strong> </strong>to help me with all the illustrations present in the article.</p><p><a href="https://medium.com/u/a00134ce20e1">Nicola Del Gobbo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea66f09eb19c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hertzy an event bus channel]]></title>
            <link>https://medium.com/cloudboost/hertzy-an-event-bus-channel-469e033671be?source=rss-a00134ce20e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/469e033671be</guid>
            <category><![CDATA[mediator]]></category>
            <category><![CDATA[events]]></category>
            <category><![CDATA[patterns]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nicola Del Gobbo]]></dc:creator>
            <pubDate>Mon, 08 Jan 2018 02:14:00 GMT</pubDate>
            <atom:updated>2018-08-20T20:52:05.019Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nxAB5npaVvtYkbrDS_4maA.png" /><figcaption>Hertzy</figcaption></figure><p>Node.js includes an <a href="https://nodejs.org/dist/latest/docs/api/events.html">event system</a> which is an implementation of the <strong>Observer</strong> pattern that is the most common used <strong>event</strong> pattern in Node.js application and for good reasons: it’s incredibly simple and useful.</p><p><strong>Hertzy</strong> adds additional messaging related features called <strong>frequency</strong> that represents a communication <strong>bus</strong> through different parts (modules) of one application that can communicate each other.</p><p>Anyone who has been used Node.js should be familiar with <a href="https://nodejs.org/dist/latest/docs/api/events.html">events</a>. This module has the responsibility to facilitate the communication between <strong>objects</strong> of your application.</p><blockquote>Much of the <strong>Node.js core API modules</strong> are built aroud an idiomatic asynchronous event-driven architecture in which certains kinds of objects (called <strong>emitter</strong>) periodically emit named events that cause Function objects (“listeners”) to be called.</blockquote><p>Sometimes you need to promote<strong> loose coupling system</strong> by ensuring that instead of components (modules) referring to each other explicitly, their interaction is handled through a central point. This can help to decouple the systems and improve the module reusability.</p><p>In implementation terms Hertzy use the <strong>mediator pattern</strong> that is ideal for application level notifications such as the communication between different subsystems that are themselves complex.</p><blockquote>Mediator Pattern Intent Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently. (<strong>GoF</strong>)</blockquote><p>The largest benefit of the mediator pattern is that it reduces the communication channels needed between objects or components in a system from <strong>many to many</strong> to just <strong>many to one</strong>.</p><p>Both pattern <strong>mediator</strong> and <strong>observer</strong> promote loose coupling, however, the mediator achieves this by having objects communicate strictly through it, while observer creates observable objects that publish events of interest to objects that are subscribed to them.</p><p>In the specific case of <strong>Hertzy</strong>, it allow to create multiple event bus represented by <strong>frequency</strong> object and every module can <strong>listen</strong> or <strong>emit</strong> an event over the selected event bus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*xSG1bM2ienfAGNAf25NiaQ.png" /><figcaption><strong>Hertzy</strong> Mediator pattern</figcaption></figure><p>As example you can think at web application where every time a user complete the signup process through the <strong>user module </strong>another module need to be notified the <strong>subscription module </strong>and on the other hand the <strong>user module</strong> need to be notified when subscription will be created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*h6grCQFSml0k1gVfmeLL8A.png" /><figcaption>Usage example</figcaption></figure><p>To start using H<strong>ertzy</strong> you have to import it in you project. After that you need to obtain a frequency or create new one. A <strong>frequency</strong> object is a channel where you can emit or listen for an event issued by other modules.</p><p>Using <strong>Hertzy</strong> you avoid to create high coupling between the previous two modules (<strong>user</strong> and <strong>subscription</strong>) and in the near future if you want split your monolithic application in a set of microservices you can do that in a more easy way and you will need to replace <strong>Hertzy</strong> with something like <a href="http://zeromq.org/"><strong>ØMQ</strong></a><strong> </strong>or <a href="https://www.rabbitmq.com/"><strong>RabbitMQ</strong></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce7bd80c826380749029374c673d1bf7/href">https://medium.com/media/ce7bd80c826380749029374c673d1bf7/href</a></iframe><p>All the API provided by H<strong>ertzy</strong> is really simple but very powerful, if you interested in using it you can find all you need on <a href="https://www.npmjs.com/package/hertzy"><strong>npm</strong></a></p><p>If you want contribute to H<strong>ertzy</strong> feel free to create a <strong>PR</strong> to its repository:</p><p><a href="https://github.com/NickNaso/hertzy">NickNaso/hertzy</a></p><blockquote><strong>Our Pledge</strong></blockquote><blockquote>In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.</blockquote><p>To go more deeply on the concepts around mediator and observer pattern you can consult the following resources:</p><p><a href="https://addyosmani.com/resources/essentialjsdesignpatterns/book/#mediatorpatternjavascript"><strong><em>Mediator pattern</em></strong></a></p><p><a href="https://addyosmani.com/resources/essentialjsdesignpatterns/book/#observerpatternjavascript"><strong><em>Observer pattern</em></strong></a></p><p><strong>Acknowledgements</strong></p><p>Thank you to all people that encourage me every day.</p><p>Mantainers and creators of <a href="https://github.com/marionettejs/backbone.radio">backbone.radio</a> a module that has inspired my work on <strong>Hertzy</strong>.</p><p>Big thank to <a href="https://twitter.com/pierluigiiannar"><strong><em>Pierluigi Iannarelli</em></strong></a><strong><em> </em></strong>that created the concept behind the new logo of <strong>Hertzy.</strong></p><p><a href="https://medium.com/u/a00134ce20e1">Nicola Del Gobbo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=469e033671be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudboost/hertzy-an-event-bus-channel-469e033671be">Hertzy an event bus channel</a> was originally published in <a href="https://medium.com/cloudboost">CloudBoost</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I ported bcrypt to new N-API]]></title>
            <link>https://medium.com/the-node-js-collection/how-i-ported-bcrypt-to-new-n-api-d0b8c9fe6136?source=rss-a00134ce20e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0b8c9fe6136</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[addons]]></category>
            <category><![CDATA[napi]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nicola Del Gobbo]]></dc:creator>
            <pubDate>Sun, 24 Dec 2017 23:34:34 GMT</pubDate>
            <atom:updated>2018-01-22T20:27:05.464Z</atom:updated>
            <content:encoded><![CDATA[<p>In a very simple way Native Addons could be considered as C/C++ code called from JavaScript.</p><p>They are a bridge between our application programming language JavaScript and native environment that is completely written in C/C++.</p><p>They allow us to call C/C++ functions and methods directly from JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oJ1O-rd1CwjJhlzsuFQrYA.png" /><figcaption>Node.js Native Addons</figcaption></figure><p>One of the most important experimental feature announced with Node.js 8 was <a href="https://nodejs.org/dist/latest/docs/api/n-api.html">N-API</a> which is aimed at reducing maintenance cost for Node.js Native Addons.</p><blockquote>It is independent from the underlying JavaScript runtime (ex <strong>V8</strong>) and is maintained as part of Node.js itself.</blockquote><blockquote>This API will be <strong>Application Binary Interface</strong> (<strong>ABI</strong>) stable across versions of Node.js. It is intended to insulate Addons from changes in the underlying JavaScript engine and allow modules compiled for one version to run on later versions of Node.js without recompilation.</blockquote><blockquote>Addons are built/packaged with the same approach/tools outlined in the section titled <a href="https://nodejs.org/dist/latest/docs/api/addons.html">C++ Addons</a>. The only difference is the set of APIs that are used by the native code. Instead of using the V8 or <a href="https://github.com/nodejs/nan">Native Abstractions for Node.js</a> APIs, the functions available in the N-API are used.</blockquote><p>As you can understand from the N-API documentation it’s completely <strong><em>JavaScript engine agnostic and it guarentees the API and ABI compatibility between different version of Node.js</em></strong>. So if you switch to a different version of Node.js you must not reinstall and recompile the addon.</p><p>I was really enthusiastic about N-API specially after I followed the talk reported above at <strong>Node Interactive 2017</strong></p><p><a href="https://youtu.be/-Oniup60Afs">N-API — Next Generation Node API for Native Modules</a></p><p>I discovered that there is a C++ Wrapper of N-API called <a href="https://github.com/nodejs/node-addon-api"><strong>node-addon-api</strong></a><strong> </strong>so I just started on experiment using it and in 4 or 5 days of my spare time I ported <a href="https://www.npmjs.com/package/bcrypt"><strong>bcrypt</strong></a> to N-API.</p><p>I started to modify the <strong>package.json</strong> file where I added the right dependencies as reported on <a href="https://github.com/nodejs/node-addon-api/blob/master/doc/setup.md">setup documentation</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b6fa9d78207c3b7205d576a3fe4fb9f/href">https://medium.com/media/7b6fa9d78207c3b7205d576a3fe4fb9f/href</a></iframe><p>The next step was to modify the <a href="https://github.com/nodejs/node-addon-api/blob/master/doc/node-gyp.md"><strong>binding.gyp</strong></a><strong> </strong>file that contains all the building configurations for the <strong>bcrypt addon</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9583b81c2836048776d7ab63f85d434b/href">https://medium.com/media/9583b81c2836048776d7ab63f85d434b/href</a></iframe><p>At the end <strong>bcrypt</strong> addon is composed by two parts one written in C++ and another written in JavaScript and as usually the JavaScript part use the native code to expose its features. I didn’t want change the JavaScript API exposed by <strong>bcrypt </strong>so I focused on the C++ part and changed the code following the <a href="https://github.com/nodejs/node-addon-api"><strong>node-addon-api</strong></a> documentation.</p><p>I started to rewrite the parts that has the responsibility to create the codes that will register a module named <strong><em>“bcrypt_napi” </em></strong>and in addition it will ensure that a function <strong>init </strong>will be called when the module is required.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a80c9935505b406b96739a30bc9ae990/href">https://medium.com/media/a80c9935505b406b96739a30bc9ae990/href</a></iframe><p><strong>bcrypt </strong>exposes synchronous and asynchronous API, so method after method I completed the refactor and now the code is as reported below</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25b948024f3cc1db34959863ecd248bd/href">https://medium.com/media/25b948024f3cc1db34959863ecd248bd/href</a></iframe><p>The last step was to execute the entire test suite and with my pleasure all tests passed successfully and they were executed more fast than the addon created using NAN. In the next days I will will perform most effective performance tests after that I will deploy my first Node.js application that will use this version of <strong>bcrypt</strong>, so stay tuned I will update you very soon.</p><p>For most of you that want start to write their Node.js native addons using N-API I just repost some useful resources that was very useful to me:</p><p><a href="https://nodejs.org/dist/latest/docs/api/addons.html"><strong>C++ Addons</strong></a></p><p><a href="https://nodejs.org/dist/latest/docs/api/n-api.html"><strong>C++ Addons N-API</strong></a></p><p><a href="https://github.com/nodejs/node-addon-api"><strong>Node Addon API</strong></a></p><p><a href="https://youtu.be/-Oniup60Afs"><strong>N-API the next API for Native Addons</strong></a></p><p><a href="https://medium.com/u/a00134ce20e1">Nicola Del Gobbo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0b8c9fe6136" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-node-js-collection/how-i-ported-bcrypt-to-new-n-api-d0b8c9fe6136">How I ported bcrypt to new N-API</a> was originally published in <a href="https://medium.com/the-node-js-collection">Node.js Collection</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Notes about Node.js Native AddOns]]></title>
            <link>https://medium.com/@nicknaso/notes-about-node-js-native-addons-32e8cf3829ff?source=rss-a00134ce20e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/32e8cf3829ff</guid>
            <category><![CDATA[addons]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[cpp]]></category>
            <category><![CDATA[native]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nicola Del Gobbo]]></dc:creator>
            <pubDate>Mon, 18 Dec 2017 02:46:07 GMT</pubDate>
            <atom:updated>2017-12-18T02:46:07.456Z</atom:updated>
            <content:encoded><![CDATA[<p>In the last year I worked a lot on Node.js native addons and my work was culminated on a talk about that at Node Interactive 2017 <a href="https://nina17.sched.com/event/Atip">https://nina17.sched.com/event/Atip</a>.</p><p>On the way I usually taken notes about native addons that now I scanned and want share with all of you.</p><p>Here you can find the PDF i generated from my notes:</p><p><a href="https://github.com/NickNaso/nodejs-native-addons-notes-2017">NickNaso/nodejs-native-addons-notes-2017</a></p><p>By the way <strong>sorry for my bad calligraphy</strong></p><p>In general if you are interested on native addons I report some</p><ul><li><a href="https://nodejs.org/dist/latest/docs/api/addons.html">C++ Addons</a></li><li><a href="https://nodejs.org/dist/latest/docs/api/n-api.html">C++ Addons — N-API</a></li><li><a href="https://youtu.be/-Oniup60Afs">N-API the next API for NAtive Addons</a></li><li><a href="https://youtu.be/KuFSDDggbOs">Node.js With Steroids video</a></li><li><a href="https://github.com/NickNaso/conf-ni-2017">Node.js With Steroids repository</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32e8cf3829ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ES6 at Packly]]></title>
            <link>https://medium.com/@nicknaso/es6-at-packly-1044ebcbc6b4?source=rss-a00134ce20e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1044ebcbc6b4</guid>
            <dc:creator><![CDATA[Nicola Del Gobbo]]></dc:creator>
            <pubDate>Mon, 04 Apr 2016 21:20:03 GMT</pubDate>
            <atom:updated>2016-04-04T21:24:54.842Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="es6" src="https://cdn-images-1.medium.com/proxy/0*KU_optsa1CQWwcKD.png" /></figure><p>Today ES6 specification known as ES2015 is almost supported in many JavaScript engines but not completely. For programmers sometimes is very frustranting cannot use some interesting and useful new language features.</p><p>In the case of ES6 JavaScript developer that want use new ES6 functionalities scuh us arrow function, class, generators, promise, maps, sets now can do that thanks to tools as babel and webpack.</p><p>In this article i explain how to setup ES6 to use it in the Node.js environment. To do that we transpile ES6 code dynamically (at runtime) thanks to <a href="https://babeljs.io/">Babel</a>.</p><p>In general there are two alternatives to transpile ES6 code, <strong>static </strong>and <strong>dynamic</strong>. Dynamic approach is convenient for experiments and development because it uses on the fly transpilation, which means that startup is slower and Babel need to be installed on the production system. We focus on the dynamic approch and we’ll configure a Node.js project to use it.</p><p>The first step is to create an empty Node.js project with your favourite IDE or simply make an empty folder and create a package.json file like this:</p><pre>{<br>  &quot;name&quot;: &quot;My Application&quot;,<br>  &quot;version&quot;: &quot;0.0.1&quot;,<br>  &quot;description&quot;: &quot;My frist Node.js ES6 Application&quot;,<br>  &quot;private&quot;: true,<br>  &quot;homepage&quot;: &quot;http://www.mywebsite.com&quot;,<br>  &quot;author&quot;: {<br>    &quot;name&quot;: &quot;NickNaso&quot;,<br>    &quot;email&quot;: &quot;nicoladelgobbo@gmail.com&quot;,<br>    &quot;url&quot;: &quot;https://github.com/NickNaso&quot;<br>  },<br>  &quot;contributors&quot;: [<br>    {<br>      &quot;name&quot;: &quot;Nicola Del Gobbo&quot;,<br>      &quot;email&quot;: &quot;nicoladelgobbo@gmail.com&quot;,<br>      &quot;url&quot;: &quot;https://github.com/NickNaso&quot;<br>    }<br>  ],<br>  &quot;bin&quot;: {<br>    &quot;start&quot;: &quot;./myapp.js&quot;<br>  },<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;babel-node ./myapp.js&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;babel-cli&quot;: &quot;*&quot;,<br>    &quot;babel-plugin-transform-regenerator&quot;: &quot;*&quot;,<br>    &quot;babel-preset-es2015-node4&quot;: &quot;*&quot;<br>  },<br>  &quot;devDependencies&quot;: {},<br>  &quot;babel&quot;: {<br>    &quot;presets&quot;: [<br>      &quot;es2015-node4&quot;<br>    ],<br>    &quot;plugins&quot;: [<br>      &quot;transform-regenerator&quot;<br>    ]<br>  }<br>}</pre><p>Now from shell launch the command:</p><pre>npm install</pre><p>At the end of this process all node modules are installed for your project and your new project structure contain a new folder <strong>node_modules</strong>.</p><p>It’s time to program and create in the root of project our first ES6 module so make a file named Person.js and edit it as reported below:</p><pre>export default class Person {<br><br>    constructor(firstName = &quot;John&quot;, lastName = &quot;Doe&quot;) {<br>        this._firstName = firstName;<br>        this._lastName = lastName;<br>    }<br><br>    get firstName() {<br>        return this._firstName;<br>    }<br><br>    set firstName(firstName) {<br>        this._firstName = firstName;<br>    }<br><br>    get lastName() {<br>        return this._lastName;<br>    }<br><br>    set lastName(lastName) {<br>        this._lastName = lastName;<br>    }<br><br>    toString() {<br>        return `You are ${this._firstName} ${this._lastName}`;<br>    }<br><br>}</pre><p>In the previous module we just created and exported a class Person with properties _firstName and _lastName and their getter, setter methods with additional toString method that have the responsability to print the properties’ values.</p><p>To complete our project we have to create a file named myapp.js that will be the application starting point as reported below:</p><pre>import Person from &#39;./Person&#39;;<br><br>let myTeam = new Set();<br><br>myTeam.add(new Person(&quot;Brendan&quot;, &quot;Eich&quot;));<br>myTeam.add(new Person(&quot;Ada&quot;, &quot;Lovelace&quot;));<br>myTeam.add(new Person(&quot;Dennis&quot;, &quot;Ritchie&quot;));<br>myTeam.add(new Person(&quot;James&quot;, &quot;Gosling&quot;));<br><br>for (let person of packlyTeam) {<br>    console.log(person.toString());<br>}</pre><p>It’s time to start our first ES6 application in Node.js environment so execute the following command:</p><pre>npm start</pre><p>The output will be something like that:</p><pre>&gt; MyApplication@0.0.1 start G:\Projects\Web\GitHub\BNode-ES6<br>&gt; babel-node ./myapp.js<br>You are Brendan Eich<br>You are Ada Lovelace<br>You are Dennis Ritchie <br>You are James Gosling<br>G:\Projects\Web\GitHub\BNode-ES6&gt;</pre><p>Now you are ready to start use all ES6 features in your Node.js project.</p><p>At <a href="https://pack.ly/">pack.ly</a> (<a href="https://www.pack.ly/create">https://www.pack.ly/create</a>) we use it because more features are very useful for us and especially because they make the javascript code more understandable at semantic level.</p><p>You can find the scaffolding of the code described in this article here:</p><p><a href="https://github.com/NickNaso/BNode-ES6">BNode-ES6</a></p><p>In this project i used Node.js 4.3.1 so in package.json i installed <strong>“babel-preset-es2015-node4” </strong>and in babel configurations under presets keys i setted <strong>“es2015-node4”</strong>. If you have different version or configuration please refer to Babel docume ntation here: <a href="https://babeljs.io/">https://babeljs.io/</a></p><p>Thank you all.</p><p><a href="https://twitter.com/NickNaso">@NickNaso</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1044ebcbc6b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MongoDB 3.2 on Ubuntu 15.10]]></title>
            <link>https://medium.com/@nicknaso/mongodb-3-2-on-ubuntu-15-10-8f7c30ca9848?source=rss-a00134ce20e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f7c30ca9848</guid>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Nicola Del Gobbo]]></dc:creator>
            <pubDate>Mon, 21 Mar 2016 22:36:37 GMT</pubDate>
            <atom:updated>2016-03-21T23:05:45.685Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*5aCEwUINaLEs1lCHfZkwuw.png" /><figcaption>MongoDB</figcaption></figure><p>This brief tutorial is going to show you how to easily install MongoDB database server on <strong>Ubuntu 15.10 </strong>without any troubles.</p><p>A stable version of MongoDB packages are already in the default Ubuntu repository. However, the version in Ubuntu’s repository isn’t the latest. If you want to install the latest version you must add a third-party repository to your system and install it from there.</p><p>You can find more information about MongoDB and its installation here:</p><p><a href="https://docs.mongodb.org/getting-started/shell/tutorial/install-mongodb-on-ubuntu/">https://docs.mongodb.org/getting-started/shell/tutorial/install-mongodb-on-ubuntu/</a></p><p>To do that, run the commands to add the repository’s key to your system. Without this key, you won’t be able to install packages from the repository.</p><pre>user@HOST:~$ <strong>sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927</strong></pre><p>Next, run the commands below to add the repository to your machine</p><pre>user@HOST:~$ <strong>echo &quot;deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse&quot; | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list</strong></pre><p>Update your system and refresh existing repositories by running the commands below.</p><pre>user@HOST:~$ <strong>sudo apt-get update</strong></pre><p>Now you can install the latest MongoDB version through the following command.</p><pre>user@HOST:~$ <strong>sudo apt-get install -y mongodb-org</strong></pre><p>If you are on Ubuntu 14.04 or 14.02 this was the final step but for the 15.10 version we have to set up some extra configuration so let’s start to check if the actual installation is good as it is now. To do that launch the command reported below.</p><pre>user@HOST:~$ <strong>sudo systemctl status mongod</strong></pre><p>If the result of this command tell us that there’s no one mongod active process on the system try to restart the system and rerun the predecing test and if we obtain the same result we need to use the following script to fix the things.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/245cd46bf5f73787469b1ef89d1fa9de/href">https://medium.com/media/245cd46bf5f73787469b1ef89d1fa9de/href</a></iframe><p>So after downloaded the script execute it as follow:</p><pre>user@HOST:~$ <strong>sudo chmod 755 enable_mongo.sh</strong><br>user@HOST:~$ <strong>sudo ./enable_mongo.sh</strong></pre><p>Now all is ok and you can try to connect to your MongoDB server by mongo client</p><pre>user@HOST:~$ <strong>mongo</strong></pre><p>In response to this command we should receive something like the picture reported below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*2Q4QoDg6UpyGXpDgH0tTQQ.png" /><figcaption>Mongo client</figcaption></figure><p>Finally we finished to install and can have fun with our MongoDB server.</p><p><a href="https://medium.com/u/a00134ce20e1">Nicola Del Gobbo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f7c30ca9848" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>