<?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 Luiz Lima on Medium]]></title>
        <description><![CDATA[Stories by Luiz Lima on Medium]]></description>
        <link>https://medium.com/@limaluizsecops?source=rss-2ab5158f49f4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Dggc8V9teG8saNZnLDqTBA@2x.jpeg</url>
            <title>Stories by Luiz Lima on Medium</title>
            <link>https://medium.com/@limaluizsecops?source=rss-2ab5158f49f4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 09:04:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@limaluizsecops/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[Complete Guide: Replacing Node.js Packages with Native APIs]]></title>
            <link>https://medium.com/@limaluizsecops/complete-guide-replacing-node-js-packages-with-native-apis-deca5f37ed54?source=rss-2ab5158f49f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/deca5f37ed54</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Luiz Lima]]></dc:creator>
            <pubDate>Wed, 30 Sep 2026 21:41:18 GMT</pubDate>
            <atom:updated>2026-09-30T21:59:50.689Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z7aWfHTfbwHRZHLL03vYIA.jpeg" /></figure><p>With the continuous updates to the Node.js ecosystem (especially LTS versions 18, 20, and the current 22), a massive amount of third-party packages has become obsolete. Removing these dependencies not only reduces the infamous node_modules black hole and improves performance, but also substantially mitigates the security risks associated with modern software development.</p><h3>The Security Risks of Third-Party Dependencies</h3><p>Over-reliance on external packages in the npm ecosystem introduces critical risks to your application. Below are the main threat vectors mitigated when we adopt native APIs:</p><ul><li><strong>Supply Chain Attacks:</strong> Attackers frequently target popular libraries. If a maintainer’s account is compromised, malicious code can be injected into a library like axios or lodash, affecting millions of projects (e.g., past cases involving the event-stream package or the sabotage of colors and faker).</li><li><strong>Transitive Vulnerabilities:</strong> Your project might require library “A”, which requires “B”, which requires “C”. A vulnerability in library “C” exposes your application. Using native code eliminates this hidden web of dependencies.</li><li><strong>Malicious Installation Scripts:</strong> npm allows the execution of scripts (like postinstall). Malicious packages (often using <em>typosquatting</em>, mimicking famous package names) can steal environment variables, SSH keys, or install backdoors simply by running npm install.</li><li><strong>Abandonware &amp; Legacy Code:</strong> Many famous packages were written years ago and are no longer actively maintained. When security flaws (CVEs) or memory leaks arise, there is no one to publish fixes.</li><li><strong>Increased Attack Surface:</strong> More lines of third-party code mean more logical bugs and vulnerabilities that could be exploited via injection (e.g., <em>Prototype Pollution</em>, very common in third-party deep clone libraries).</li></ul><blockquote><strong><em>💡 Security Tip:</em></strong><em> When importing native Node modules, get into the habit of using the </em><em>node: prefix (e.g., </em><em>import fs from &#39;node:fs&#39;). This guarantees that Node loads the internal module and prevents a malicious package installed in your </em><em>node_modules with the name </em><em>fs or </em><em>crypto from intercepting the import.</em></blockquote><h3>The Complete List of Native Replacements</h3><h4>1. HTTP Requests &amp; API Consumption</h4><p><em>Replaceable packages: axios, node-fetch, request, got</em></p><p>Since Node 18, there is no need for external libraries for simple requests. The global <strong>Fetch API</strong> solves the problem with the exact same syntax used in browsers:</p><p>JavaScript</p><pre>// Before: import axios from &#39;axios&#39;; axios.get(...)<br>// Now (Native):<br>const response = await fetch(&#39;https://api.example.com/data&#39;);<br>const data = await response.json();<br>console.log(data);</pre><h4>2. Native TypeScript Support</h4><p><em>Replaceable packages: ts-node, tsx, esbuild (for execution)</em></p><p>Node.js now has native support for executing TypeScript files directly, without the need for intermediate build tools in your development environment.</p><p><strong>The Catch:</strong> Node only <em>strips</em> the typings (using the --experimental-strip-types flag) to run the code; it <strong>does not perform type-checking</strong>. You still need to run tsc in your CI/CD pipeline to validate types, but locally, running the project just got much simpler and faster. <em>(See more in the </em><a href="https://nodejs.org/api/typescript.html"><em>official documentation</em></a><em>).</em></p><h4>3. Unit Testing, Mocks &amp; Coverage</h4><p><em>Replaceable packages: jest, mocha, chai, sinon, nyc/istanbul</em></p><p>The native node:test and node:assert modules are extremely powerful and allow you to skip heavy Jest configurations. To run tests with coverage, simply execute node --test --experimental-test-coverage.</p><p>JavaScript</p><pre>import test from &#39;node:test&#39;;<br>import assert from &#39;node:assert&#39;;<br><br>test(&#39;should add two numbers correctly&#39;, () =&gt; {<br>  assert.strictEqual(1 + 1, 2);<br>});</pre><h4>4. Cryptography with Web Crypto API</h4><p><em>Replaceable packages: crypto-js, bcrypt</em></p><p>Utilize the native Web Crypto API to access cryptographic features like SHA, Argon2, and secure key generation, following web standards <em>(See more in the </em><a href="https://nodejs.org/api/webcrypto.html"><em>official documentation</em></a><em>)</em>.</p><h4>5. Reading Environment Variables</h4><p><em>Replaceable packages: dotenv, cross-env</em></p><p>Say goodbye to dotenv. Starting from Node 20.6.0, you can inject environment variables directly at startup or via code:</p><p>Bash</p><pre># Via terminal:<br>node --env-file=.env app.js</pre><p>JavaScript</p><pre>// Or directly in your code:<br>process.loadEnvFile();<br>console.log(process.env.MY_VARIABLE);</pre><h4>6. Monitoring &amp; Auto-Restart (Watch Mode)</h4><p><em>Replaceable packages: nodemon, ts-node-dev</em></p><p>Node has solved this natively. Just run:</p><p>node --watch app.js</p><h4>7. URL &amp; Query String Manipulation</h4><p><em>Replaceable packages: query-string, url-parse, qs (for basic cases)</em></p><p>The global URL and URLSearchParams classes handle URL construction and destructuring perfectly:</p><p>JavaScript</p><pre>const params = new URLSearchParams({ page: 2, sort: &#39;desc&#39; });<br>console.log(params.toString()); // page=2&amp;sort=desc</pre><h4>8. Base64 Encoding</h4><p><em>Replaceable packages: btoa, atob</em></p><p>Thanks to standardization efforts (WinterCG), btoa and atob are globally available in Node to ensure isomorphic compatibility (running the same code across Node, Deno, Bun, and the Browser). However, in purely Node environments, using Buffer remains the <strong>most performant</strong> way:</p><p>JavaScript</p><pre>const stringToEncode = &quot;Hello, world!&quot;;<br>const encodedData = Buffer.from(stringToEncode).toString(&#39;base64&#39;);<br>const decodedData = Buffer.from(encodedData, &#39;base64&#39;).toString(&#39;utf-8&#39;);</pre><h4>9. Promise-Based Timers (Sleep/Delay)</h4><p><em>Replaceable packages: delay, sleep</em></p><p>The node:timers/promises module provides setTimeout and setImmediate wrapped as Promises, cleaning up asynchronous code:</p><p>JavaScript</p><pre>import { setTimeout } from &#39;node:timers/promises&#39;;<br><br>console.log(&#39;Waiting...&#39;);<br>await setTimeout(2000); // Pauses execution for 2s without blocking the thread<br>console.log(&#39;Done!&#39;);</pre><h4>10. File System Operations (fs-extra)</h4><p><em>Replaceable packages: fs-extra, rimraf, mkdirp, cp</em></p><p>The native node:fs/promises module has been supercharged:</p><ul><li>Copy files/directories recursively: fs.cp(src, dest, { recursive: true })</li><li>Delete entire folders (rimraf): fs.rm(path, { recursive: true, force: true })</li><li>Create nested folders (mkdirp): fs.mkdir(path, { recursive: true })</li></ul><h4>11. File Pattern Matching (Globbing)</h4><p><em>Replaceable packages: glob, fast-glob, globby</em></p><p>Starting with Node 22, you can use the native fs.glob API directly.</p><h4>12. Deep Object Cloning (Deep Clone)</h4><p><em>Replaceable packages: lodash.clonedeep, clone-deep</em></p><p>Since Node 17, the global structuredClone() function allows you to create deep copies natively, even supporting circular references, leaving heavy libraries like Lodash in the past.</p><p>JavaScript</p><pre>const originalObject = { a: 1, nested: { b: 2 } };<br>const copy = structuredClone(originalObject);</pre><h4>13. Safe Stream Chaining</h4><p><em>Replaceable packages: pump, multipipe</em></p><p>Use stream.pipeline from node:stream or its promise-based version node:stream/promises to properly handle errors and memory release when piping multiple streams.</p><h4>14. Terminal Colors &amp; Styles</h4><p><em>Replaceable packages: chalk, colors</em></p><p>In Node 21.7+, you no longer need to download dependencies to colorize your terminal logs. The util.styleText function solves this elegantly:</p><p>JavaScript</p><pre>import { styleText } from &#39;node:util&#39;;<br><br>console.log(styleText(&#39;green&#39;, &#39;Success! Dependency removed.&#39;));<br>console.log(styleText([&#39;red&#39;, &#39;bold&#39;], &#39;Critical error.&#39;));</pre><h4>15. Unique Identifiers (UUID)</h4><p><em>Replaceable packages: uuid, nanoid</em></p><p>Use crypto.randomUUID(). If you need time-based sorting, randomUUIDv7 is also available starting from Node.js v26.</p><h4>16. CLI Argument Parsing</h4><p><em>Replaceable packages: minimist, yargs</em></p><p>If you build command-line tools, the native util.parseArgs() is all you need.</p><h4>17. WebSocket Clients</h4><p><em>Replaceable packages: ws</em></p><p>The global WebSocket object is supported natively starting from Node 22.</p><h4>18. Parallel Workers / Threads</h4><p><em>Replaceable packages: webworker-threads, threads</em></p><p>Use the native node:worker_threads module for heavy multi-threaded execution (like image processing or math calculations) without blocking the main Event Loop.</p><h3>Conclusion: Less is More</h3><p>Replacing legacy dependencies with native APIs isn’t just about the vanity of having a leaner node_modules folder. It is an architectural and strategic move that improves cold start times, reduces your attack surface, and eases the long-term maintenance of your application.</p><p>Remember to always validate the compatibility and version of your production environment before refactoring these vital dependencies, especially when using flags with the --experimental prefix.</p><p><strong>What about you? Which package are you tired of seeing in your </strong>package.json<strong> and will replace with native code today? Let me know in the comments!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=deca5f37ed54" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>