<?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 Farhad on Medium]]></title>
        <description><![CDATA[Stories by Farhad on Medium]]></description>
        <link>https://medium.com/@farhad.gulizada?source=rss-164db0c8a865------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jqDa0uBVoEsOB9U47s7O3g.png</url>
            <title>Stories by Farhad on Medium</title>
            <link>https://medium.com/@farhad.gulizada?source=rss-164db0c8a865------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 04:37:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@farhad.gulizada/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[Node.js Beginner Series]]></title>
            <link>https://medium.com/@farhad.gulizada/node-js-beginner-series-81036c25989f?source=rss-164db0c8a865------2</link>
            <guid isPermaLink="false">https://medium.com/p/81036c25989f</guid>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Farhad]]></dc:creator>
            <pubDate>Tue, 20 Jan 2026 09:07:11 GMT</pubDate>
            <atom:updated>2026-01-20T09:07:11.464Z</atom:updated>
            <content:encoded><![CDATA[<h3>Node.js — Beginner’s Guide</h3><p>This list covers the topics devised for beginners:</p><p>1. <a href="https://medium.com/p/02aeac0bf8ea/edit?source=your_stories_page--------------------------------------------">Console</a> <br>2. <a href="https://medium.com/@farhad.gulizada/beginner-series-global-objects-in-node-js-5f0cb4ba7d86?source=your_stories_page--------------------------------------------">Globals</a> <br>3. <a href="https://medium.com/p/bb5688b60124/edit?source=your_stories_page--------------------------------------------">Timers</a> <br>4. <a href="https://medium.com/p/b19eea7aefeb/edit?source=your_stories_page--------------------------------------------">Path</a> <br>5. <a href="https://medium.com/@farhad.gulizada/url-anatomy-62d878681e9d?source=your_stories_page--------------------------------------------">URL</a> <br>6. <a href="https://medium.com/p/fc52886e4ca0/edit?source=your_stories_page--------------------------------------------">Query strings </a><br>7. <a href="https://medium.com/p/4202178e7302/edit?source=your_stories_page--------------------------------------------">OS</a> <br>8. <a href="https://medium.com/@farhad.gulizada/tty-in-nodejs-cb82215a7942?source=your_stories_page--------------------------------------------">TTY</a> <br>9. <a href="https://medium.com/p/54b6df699a39/edit?source=your_stories_page--------------------------------------------">Readline</a> <br>10. <a href="https://medium.com/@farhad.gulizada/utils-in-node-js-e877e84acd66?source=your_stories_page--------------------------------------------">Utilities</a> <br>11. <a href="https://medium.com/p/d20be6b81104/edit?source=your_stories_page--------------------------------------------">String decoder</a> <br>12. <a href="https://medium.com/@farhad.gulizada/beginner-series-events-in-node-js-5754b710c86d?source=your_stories_page--------------------------------------------">Events</a> <br>13. <a href="https://medium.com/@farhad.gulizada/node-js-assertion-testing-guide-d1fc5771a9e6?source=your_stories_page--------------------------------------------">Assertion testing</a> <br>14. <a href="https://medium.com/p/61b78616442b/edit?source=your_stories_page--------------------------------------------">Modules: CommonJS </a><br>15. <a href="https://medium.com/p/949a1236d03e/edit?source=your_stories_page--------------------------------------------">Modules: ECMAScript </a><br>16. <a href="https://medium.com/p/0ee4c7ea39d9/edit?source=your_stories_page--------------------------------------------">Modules: Packages</a> <br>17. <a href="https://medium.com/@farhad.gulizada/repl-read-eval-print-loop-in-nodejs-3babd9eee72c?source=your_stories_page--------------------------------------------">REPL</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81036c25989f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inspector in Node.js — Advanced Series]]></title>
            <link>https://javascript.plainenglish.io/inspector-in-node-js-advanced-series-c379e304a760?source=rss-164db0c8a865------2</link>
            <guid isPermaLink="false">https://medium.com/p/c379e304a760</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[debugging-tools]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[node]]></category>
            <dc:creator><![CDATA[Farhad]]></dc:creator>
            <pubDate>Fri, 18 Jul 2025 16:01:03 GMT</pubDate>
            <atom:updated>2025-07-18T16:01:03.995Z</atom:updated>
            <content:encoded><![CDATA[<h3>Inspector in Node.js — Advanced Series</h3><h3>Introduction</h3><p>The Inspector module provides an interface for debugging Node.js applications using Chrome DevTools Protocol.</p><h3>Basic Usage</h3><h4>Starting Inspector</h4><pre>const inspector = require(&#39;node:inspector&#39;);<br>inspector.open(); // Starts inspector on default port 9229</pre><h3>Connecting to DevTools</h3><p>After starting, open Chrome and navigate to:</p><pre>chrome://inspect</pre><h3>Key Features</h3><h4>Console Integration</h4><pre>// Log to inspector console<br>inspector.console.log(&#39;Debug message&#39;);</pre><h4>CPU Profiling</h4><pre>inspector.profiler.start();<br>// Run code to profile<br>inspector.profiler.stop();</pre><h3>Common Methods</h3><pre>Method                     Description<br>------                     -----------<br>open([port[, host[, wait]]])  Start inspector server<br>close()                    Stop inspector server<br>url()                      Get inspector URL<br>waitForDebugger()          Pause execution until debugger connects</pre><h3>Debugging Example</h3><pre>const inspector = require(&#39;node:inspector&#39;);<br><br>// Start inspector and wait for connection<br>inspector.open(9229, &#39;127.0.0.1&#39;, true);<br><br>// Your application code<br>function calculate() {<br>  const a = 5;<br>  const b = 10;<br>  debugger; // Breakpoint here<br>  return a + b;<br>}<br><br>calculate();</pre><h3>Advanced Features</h3><h4>Heap Snapshots</h4><pre>const { Session } = require(&#39;node:inspector&#39;);<br>const session = new Session();<br>session.connect();<br><br>session.post(&#39;HeapProfiler.takeHeapSnapshot&#39;, (err, result) =&gt; {<br>  // Process snapshot<br>});</pre><h3>Command Line Usage</h3><p>You can also start Node.js with inspector:</p><pre>node --inspect yourScript.js</pre><h3>Important Notes</h3><ul><li>Inspector should not be used in production</li><li>Exposes debugging interface that could be security risk</li><li>For production debugging, use logging instead</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c379e304a760" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/inspector-in-node-js-advanced-series-c379e304a760">Inspector in Node.js — Advanced Series</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asynchronous Context Tracking in Node.js — Advanced Series]]></title>
            <link>https://medium.com/@farhad.gulizada/asynchronous-context-tracking-in-node-js-advanced-series-d23f9a04d729?source=rss-164db0c8a865------2</link>
            <guid isPermaLink="false">https://medium.com/p/d23f9a04d729</guid>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Farhad]]></dc:creator>
            <pubDate>Thu, 17 Jul 2025 16:03:03 GMT</pubDate>
            <atom:updated>2025-07-17T16:03:03.957Z</atom:updated>
            <content:encoded><![CDATA[<h3>Asynchronous Context Tracking in Node.js — Advanced Series</h3><h3>1. AsyncLocalStorage Basics</h3><p>Creates isolated storage that persists through asynchronous operations.</p><p>Example implementation:</p><pre>const storage = new AsyncLocalStorage();<br><br>storage.run(new Map(), () =&gt; {<br>  storage.getStore().set(&#39;data&#39;, 123);<br>  setTimeout(() =&gt; {<br>    console.log(storage.getStore().get(&#39;data&#39;)); // Outputs: 123<br>  }, 100);<br>});</pre><h3>2. Creating Custom Async Contexts</h3><p>For specialized asynchronous operations, you can create dedicated context containers.</p><p>Basic usage:</p><pre>const context = new AsyncResource(&#39;CustomContext&#39;);<br>context.runInAsyncScope(() =&gt; {<br>  // Operations here maintain their own context<br>});</pre><h3>Core Functionality Overview</h3><pre>Method               Purpose                                      Sample Usage<br>------               -------                                      -----------<br>run()                Establishes context boundary                storage.run(ctx, callback)<br>getStore()           Retrieves current context                   storage.getStore()<br>disable()            Turns off context tracking                  storage.disable()<br>bind()               Links function to context                   storage.bind(fn)<br>snapshot()           Creates context copy                        storage.snapshot()</pre><h3>Practical Applications</h3><h4>Maintaining Request State</h4><pre>const requestStorage = new AsyncLocalStorage();<br><br>server.on(&#39;request&#39;, (req, res) =&gt; {<br>  requestStorage.run({ requestId: generateId() }, () =&gt; {<br>    processRequest();<br>  });<br>});<br><br>function logMessage(msg) {<br>  const context = requestStorage.getStore();<br>  console.log(`[${context.requestId}] ${msg}`);<br>}</pre><h4>Working with Async/Await</h4><pre>async function processData() {<br>  await storage.run(new Map(), async () =&gt; {<br>    storage.getStore().set(&#39;status&#39;, &#39;processing&#39;);<br>    await databaseOperation();<br>  });<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d23f9a04d729" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript Modules in Node.js — Advanced Series]]></title>
            <link>https://medium.com/@farhad.gulizada/typescript-modules-in-node-js-advanced-series-9eac0bcc88dc?source=rss-164db0c8a865------2</link>
            <guid isPermaLink="false">https://medium.com/p/9eac0bcc88dc</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Farhad]]></dc:creator>
            <pubDate>Wed, 16 Jul 2025 15:21:29 GMT</pubDate>
            <atom:updated>2025-07-16T15:21:29.704Z</atom:updated>
            <content:encoded><![CDATA[<h3>TypeScript Modules in Node.js — Advanced Series</h3><h3>TypeScript Support Overview</h3><p>Node.js provides two approaches for TypeScript support:</p><pre>// Lightweight built-in support<br>node --experimental-transform-types your-file.ts<br><br>// Full support via third-party packages<br>npx tsx your-file.ts</pre><h3>Core Features</h3><h4>Built-in Type Stripping</h4><pre>// Example.ts - TypeScript with inline types<br>function greet(name: string): string {<br>  return `Hello ${name}`;<br>}</pre><p>Becomes when executed:</p><pre>function greet(name) {<br>  return `Hello ${name}`;<br>}</pre><h4>Module System Detection</h4><pre>File Extension   Module System<br>-------------   -------------<br>.mts            Always ESM<br>.cts            Always CommonJS<br>.ts             Depends on package.json</pre><h3>Configuration</h3><h4>Recommended tsconfig</h4><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;target&quot;: &quot;esnext&quot;,<br>    &quot;module&quot;: &quot;nodenext&quot;,<br>    &quot;noEmit&quot;: true,<br>    &quot;verbatimModuleSyntax&quot;: true<br>  }<br>}</pre><h3>Key Limitations</h3><ol><li>No tsconfig.json Support</li></ol><ul><li>Path aliases not transformed</li><li>Only basic type stripping</li></ul><p>2. Unsupported Syntax</p><ul><li>Enums (without — experimental-transform-types)</li><li>Parameter properties</li><li>Namespace runtime code</li></ul><h3>Best Practices</h3><h4>Type-Only Imports</h4><pre>import type { SomeType } from &#39;./module&#39;;<br>import { value, type ValueType } from &#39;./another&#39;;</pre><h4>File Extensions</h4><pre>// Required in Node.js<br>import &#39;./file.ts&#39;; <br>require(&#39;./file.ts&#39;);</pre><h3>Production Considerations</h3><ul><li>Memory: Each worker needs ~10MB</li><li>Startup: Additional compilation time</li><li>Compatibility: Verify Node.js version support</li></ul><h3>Complete Example</h3><h4>Express Server with TypeScript</h4><pre>import express from &#39;express&#39;;<br><br>const app = express();<br><br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;TypeScript Server&#39;);<br>});<br><br>app.listen(3000);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9eac0bcc88dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trace Events in Node.js — Advanced Series]]></title>
            <link>https://medium.com/@farhad.gulizada/trace-events-in-node-js-advanced-series-efd1f518fa49?source=rss-164db0c8a865------2</link>
            <guid isPermaLink="false">https://medium.com/p/efd1f518fa49</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[debugging-tools]]></category>
            <category><![CDATA[node]]></category>
            <dc:creator><![CDATA[Farhad]]></dc:creator>
            <pubDate>Sun, 13 Jul 2025 16:01:43 GMT</pubDate>
            <atom:updated>2025-07-13T16:01:43.796Z</atom:updated>
            <content:encoded><![CDATA[<h3>Trace Events in Node.js — Advanced Series</h3><h3>Introduction</h3><p>Trace Events provide detailed diagnostics about Node.js application performance and behavior.</p><h3>Basic Usage</h3><h4>Enabling Tracing</h4><pre>const trace_events = require(&#39;node:trace_events&#39;);<br>const tracing = trace_events.createTracing({<br>  categories: [&#39;node.perf&#39;, &#39;node&#39;]<br>});<br>tracing.enable();</pre><h3>Disabling Tracing</h3><pre>tracing.disable();</pre><h3>Key Concepts</h3><h4>Tracing Categories</h4><p>Common categories include:</p><pre>node        - Core Node.js events<br>node.perf   - Performance measurements<br>v8          - V8 JavaScript engine events</pre><h4>Recording Traces</h4><pre>const fs = require(&#39;node:fs&#39;);<br>const session = new trace_events.TracingSession();<br>session.start({ categories: [&#39;node&#39;] });<br><br>// Your application code here<br><br>session.stop().then((traceData) =&gt; {<br>  fs.writeFileSync(&#39;trace.json&#39;, JSON.stringify(traceData));<br>});</pre><h3>Common Methods</h3><pre>Method                      Description<br>------                      -----------<br>createTracing(options)      Creates tracing session<br>enable()                    Starts recording<br>disable()                   Stops recording<br>getEnabledCategories()      Returns active categories</pre><h3>Practical Example</h3><h4>Performance Analysis</h4><pre>const tracer = trace_events.createTracing({<br>  categories: [&#39;node.perf&#39;]<br>});<br><br>tracer.enable();<br><br>// Run performance-critical code<br>tracer.disable();</pre><h3>Command Line Usage</h3><p>Start Node.js with tracing:</p><pre>node --trace-event-categories=node,node.perf app.js</pre><h3>Viewing Traces</h3><ol><li>Record trace to file</li><li>Open Chrome DevTools</li><li>Go to “Performance” tab</li><li>Load the trace file</li></ol><h3>Important Notes</h3><ul><li>Tracing impacts performance</li><li>Use specific categories to minimize overhead</li><li>Trace files can grow large quickly</li><li>Not recommended for production use</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efd1f518fa49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reports in Node.js — Advanced Series]]></title>
            <link>https://medium.com/@farhad.gulizada/reports-in-node-js-advanced-series-f1b065b4b184?source=rss-164db0c8a865------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1b065b4b184</guid>
            <category><![CDATA[debugging-tools]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[node]]></category>
            <dc:creator><![CDATA[Farhad]]></dc:creator>
            <pubDate>Sat, 12 Jul 2025 16:02:58 GMT</pubDate>
            <atom:updated>2025-07-12T16:02:58.836Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reports in Node.js — Advanced Series</h3><h3>Introduction</h3><p>Diagnostic Reports generate comprehensive JSON snapshots of a Node.js application’s state, useful for troubleshooting issues in various environments.</p><h3>Core Functionality</h3><ul><li>Captures JavaScript and native stack traces</li><li>Includes memory and CPU usage statistics</li><li>Records system and process information</li><li>Supports both manual and automatic triggering</li></ul><h3>Basic Usage Examples</h3><h4>Creating a Report File</h4><pre>const process = require(&#39;process&#39;);<br>process.report.writeReport(); // Generates report file</pre><h4>Accessing Report Data</h4><pre>const currentReport = process.report.getReport();<br>console.log(currentReport);</pre><h3>Configuration Settings</h3><pre>Setting                   Purpose<br>-------                   -------<br>directory                 Specifies output folder<br>filename                  Defines custom filename format<br>compact                   Produces minified JSON output<br>signal                    Sets triggering signal<br>reportOnFatalError        Auto-generates on fatal errors  <br>reportOnSignal            Auto-generates on specified signals<br>reportOnUncaughtException Auto-generates on uncaught exceptions</pre><h3>Practical Implementations</h3><h4>Customizing Report Output</h4><pre>process.report.directory = &#39;/var/log/node_reports&#39;;<br>process.report.filename = &#39;app_diagnostics.json&#39;;<br>process.report.writeReport();</pre><h4>Error-Specific Reporting</h4><pre>try {<br>  criticalProcess();<br>} catch (error) {<br>  process.report.writeReport(error);<br>}</pre><h3>Report Content Structure</h3><p>Typical reports contain:</p><ul><li>Process metadata and timestamps</li><li>JavaScript call stacks</li><li>Native stack information</li><li>Memory allocation details</li><li>System resource metrics</li><li>Environment configuration</li></ul><h3>Command Line Interface</h3><p>Generate reports using Node.js CLI options:</p><pre>node --report-uncaught-exception server.js<br>node --report-on-signal=SIGUSR2 worker.js<br>node --report-directory=./reports app.js</pre><h3>Important Considerations</h3><ul><li>Reports may impact application performance</li><li>Output files can consume significant disk space</li><li>Contains sensitive environment information</li><li>Recommended primarily for debugging purposes</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1b065b4b184" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VM(Virtual Execution) Environments in Node.js — Advanced Series]]></title>
            <link>https://medium.com/@farhad.gulizada/vm-virtual-execution-environments-in-node-js-advanced-series-5342c0c1df75?source=rss-164db0c8a865------2</link>
            <guid isPermaLink="false">https://medium.com/p/5342c0c1df75</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[vm]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[sandbox]]></category>
            <dc:creator><![CDATA[Farhad]]></dc:creator>
            <pubDate>Fri, 11 Jul 2025 16:01:47 GMT</pubDate>
            <atom:updated>2025-07-11T16:01:47.726Z</atom:updated>
            <content:encoded><![CDATA[<h3>VM(Virtual Execution) Environments in Node.js — Advanced Series</h3><h3>Overview</h3><p>The VM functionality lets you run JavaScript code in separate, self-contained worlds. This helps isolate different parts of your application and control what resources they can access.</p><h3>Core Features</h3><h4>Isolated Code Execution</h4><p>Run code without affecting your main application:</p><pre>const vm = require(&#39;node:vm&#39;);<br>const sandbox = { total: 10 };<br><br>// Create protected environment<br>const safeSpace = vm.createContext(sandbox);<br><br>// Run code in isolation<br>vm.runInContext(&#39;total *= 2&#39;, safeSpace);<br>console.log(sandbox.total); // 20</pre><h4>Precompiled Operations</h4><p>Prepare code for efficient reuse:</p><pre>const doubleScript = new vm.Script(&#39;value * 2&#39;);<br>const dataEnv = vm.createContext({ value: 8 });<br><br>console.log(doubleScript.runInContext(dataEnv)); // 16</pre><h3>Main Functions</h3><pre>Function               Description<br>--------               -----------<br>makeSandbox()          Creates protected environment  <br>runSandboxed()         Executes code in sandbox<br>runNewSandbox()        Makes and runs in new sandbox<br>runHere()              Runs in current environment<br>isSandbox()            Checks if object is sandbox</pre><h3>Usage Examples</h3><h4>Loading External Configs</h4><pre>const configSpace = vm.createContext({ options: {} });<br>vm.runInContext(&#39;options.timeout = 5000&#39;, configSpace);<br>// configSpace.options now has { timeout: 5000 }</pre><h4>Conditional Logic</h4><pre>const check = &#39;score &gt; 100 ? &quot;Pass&quot; : &quot;Fail&quot;&#39;;<br>console.log(vm.runInNewContext(check, { score: 85 })); // &quot;Fail&quot;</pre><h3>Important Notes</h3><ul><li>Not completely hack-proof</li><li>Best for trusted code only</li><li>Changes stay within given sandbox</li><li>Some performance impact</li></ul><h3>Efficiency Tips</h3><ul><li>Reuse compiled scripts</li><li>Share sandboxes when possible</li><li>Use runNewSandbox for single runs</li><li>Hide errors in production</li></ul><h3>Practical Applications</h3><h4>Extending Functionality</h4><pre>const pluginEnv = vm.createContext({<br>  print: console.log,<br>  version: &#39;2.3&#39;<br>});<br><br>function addFeature(code) {<br>  try {<br>    return vm.runInContext(code, pluginEnv);<br>  } catch (e) {<br>    console.log(&#39;Extension failed:&#39;, e);<br>  }<br>}</pre><h3>Code Testing</h3><pre>function verifyCode(code) {<br>  const testEnv = vm.createContext({<br>    check: require(&#39;assert&#39;),<br>    input: 100<br>  });<br>  return vm.runInContext(code, testEnv);<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5342c0c1df75" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WebAssembly System Interface (WASI) in Node.js — Advanced Series]]></title>
            <link>https://medium.com/@farhad.gulizada/webassembly-system-interface-wasi-in-node-js-advanced-series-fb7627f8ff59?source=rss-164db0c8a865------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb7627f8ff59</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[webassembly]]></category>
            <category><![CDATA[wasm]]></category>
            <dc:creator><![CDATA[Farhad]]></dc:creator>
            <pubDate>Thu, 10 Jul 2025 16:03:13 GMT</pubDate>
            <atom:updated>2025-07-10T16:03:13.875Z</atom:updated>
            <content:encoded><![CDATA[<h3>WebAssembly System Interface (WASI) in Node.js — Advanced Series</h3><h3>Overview</h3><p>WASI enables WebAssembly modules to securely interact with system resources like files and environment variables. This experimental feature provides sandboxed access to operating system functions.</p><h3>Basic Setup</h3><h4>Initializing WASI</h4><pre>const { WASI } = require(&#39;node:wasi&#39;);<br>const wasiInstance = new WASI({<br>  version: &#39;preview1&#39;,<br>  args: process.argv,<br>  env: process.env<br>});</pre><h4>Running a WebAssembly Module</h4><pre>const wasmCode = await WebAssembly.compile(fs.readFileSync(&#39;module.wasm&#39;));<br>const instance = await WebAssembly.instantiate(wasmCode, {<br>  wasi_snapshot_preview1: wasiInstance.wasiImport<br>});<br>wasiInstance.start(instance);</pre><h3>Key Features</h3><h4>File System Access</h4><p>Control which directories WebAssembly can access:</p><pre>new WASI({<br>  preopens: {<br>    &#39;/sandbox&#39;: &#39;/actual/path/on/host&#39;<br>  }<br>});</pre><h4>Command Line Arguments</h4><p>Pass custom arguments to WebAssembly:</p><pre>new WASI({<br>  args: [&#39;custom_program_name&#39;, &#39;--verbose&#39;, &#39;input.txt&#39;]<br>});</pre><h3>Important Methods</h3><pre>Method               Description<br>------               -----------<br>getImportObject()    Returns import object for WebAssembly<br>start(instance)      Begins execution of WASI module<br>initialize(instance) Initializes reactor-style modules</pre><h3>Security Considerations</h3><ul><li>Currently doesn’t provide complete sandboxing</li><li>File system access can potentially be bypassed</li><li>Not recommended for untrusted code</li><li>This is experimental (API may change)</li></ul><h3>Example Workflow</h3><ol><li>Write WebAssembly (WAT format example):</li></ol><pre>(module<br>  (import &quot;wasi_snapshot_preview1&quot; &quot;fd_write&quot; (func $write (param i32 i32 i32 i32) (result i32)))<br>  (memory 1) (export &quot;memory&quot; (memory 0))<br>  (data (i32.const 8) &quot;Hello\\n&quot;)<br>  (func $main (export &quot;_start&quot;)<br>    ;; System call to write to stdout<br>    (call $write (i32.const 1) (i32.const 8) (i32.const 6) (i32.const 0))<br>    drop<br>  )<br>)</pre><p>2. Convert to WASM:</p><pre>wat2wasm hello.wat -o hello.wasm</pre><p>3. Run in Node.js:</p><pre>const { WASI } = require(&#39;node:wasi&#39;);<br>const fs = require(&#39;node:fs&#39;);<br><br>(async () =&gt; {<br>  const wasi = new WASI();<br>  const wasm = await WebAssembly.compile(fs.readFileSync(&#39;hello.wasm&#39;));<br>  const instance = await WebAssembly.instantiate(wasm, wasi.getImportObject());<br>  wasi.start(instance); // Prints &quot;Hello&quot;<br>})();</pre><h3>Current Limitations</h3><ul><li>Experimental status (API may change)</li><li>Limited security guarantees</li><li>Some WASI features not yet implemented</li><li>Requires specific version flag in older Node.js versions</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb7627f8ff59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[V8 Engine in Node.js — Advanced Series]]></title>
            <link>https://medium.com/@farhad.gulizada/v8-engine-in-node-js-advanced-series-78c277fb294b?source=rss-164db0c8a865------2</link>
            <guid isPermaLink="false">https://medium.com/p/78c277fb294b</guid>
            <category><![CDATA[v8]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[vm]]></category>
            <dc:creator><![CDATA[Farhad]]></dc:creator>
            <pubDate>Thu, 10 Jul 2025 16:03:12 GMT</pubDate>
            <atom:updated>2025-07-10T16:03:12.553Z</atom:updated>
            <content:encoded><![CDATA[<h3>V8 Engine in Node.js — Advanced Series</h3><h3>Overview</h3><p>The V8 module provides access to Node.js’s underlying JavaScript engine capabilities. These APIs offer insights into memory usage, performance characteristics, and engine configuration.</p><h3>Memory Inspection</h3><h4>Heap Statistics</h4><p>Get detailed memory allocation metrics:</p><pre>const v8 = require(&#39;node:v8&#39;);<br>const stats = v8.getHeapStatistics();<br>console.log(&#39;Total heap size:&#39;, stats.total_heap_size);</pre><h4>Heap Space Breakdown</h4><p>View memory segment details:</p><pre>const spaces = v8.getHeapSpaceStatistics();<br>spaces.forEach(space =&gt; {<br>  console.log(`${space.space_name}: ${space.space_used_size} bytes used`);<br>});</pre><h3>Performance Tools</h3><h4>Heap Snapshots</h4><p>Capture memory state for analysis:</p><pre>const snapshotStream = v8.getHeapSnapshot();<br>const writeStream = fs.createWriteStream(&#39;heap.json&#39;);<br>snapshotStream.pipe(writeStream);</pre><h4>Code Statistics</h4><p>Inspect compiled code memory usage:</p><pre>const codeStats = v8.getHeapCodeStatistics();<br>console.log(&#39;Bytecode size:&#39;, codeStats.bytecode_and_metadata_size);</pre><h3>Engine Configuration</h3><h3>Version Compatibility</h3><p>Check script cache compatibility:</p><pre>const cacheTag = v8.cachedDataVersionTag();<br>console.log(&#39;Cache version:&#39;, cacheTag);</pre><h4>Runtime Flags</h4><p>Modify engine behavior (use cautiously):</p><pre>// Enable garbage collection logging<br>v8.setFlagsFromString(&#39;--trace_gc&#39;);<br>setTimeout(() =&gt; {<br>  v8.setFlagsFromString(&#39;--notrace_gc&#39;); <br>}, 5000);</pre><h3>Heap Analysis for C++</h3><p>Inspect native memory allocations:</p><pre>const cppStats = v8.getCppHeapStatistics(&#39;detailed&#39;);<br>console.log(&#39;C++ heap usage:&#39;, cppStats.used_size_bytes);</pre><h3>Key Considerations</h3><ul><li>Memory snapshots may double heap usage temporarily</li><li>Engine flags affect entire process — modify carefully</li><li>Statistics may vary between V8 versions</li><li>Some features are experimental and may change</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78c277fb294b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Standalone Executable Applications in Node.js — Advanced Series]]></title>
            <link>https://medium.com/@farhad.gulizada/standalone-executable-applications-in-node-js-advanced-series-f95256ac4d37?source=rss-164db0c8a865------2</link>
            <guid isPermaLink="false">https://medium.com/p/f95256ac4d37</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[nodejs-app-development]]></category>
            <dc:creator><![CDATA[Farhad]]></dc:creator>
            <pubDate>Wed, 09 Jul 2025 16:01:45 GMT</pubDate>
            <atom:updated>2025-07-09T16:01:45.166Z</atom:updated>
            <content:encoded><![CDATA[<h3>Standalone Executable Applications in Node.js — Advanced Series</h3><h3>Overview</h3><p>Node.js provides a method to bundle applications into self-contained executables that can run without requiring Node.js installation on the target system. This packages your JavaScript code directly into a modified Node.js binary.</p><h3>How It Works</h3><p>The process involves:</p><ol><li>Preparing your application code</li><li>Generating a special bundle file</li><li>Injecting it into a Node.js binary copy</li><li>Creating a final executable</li></ol><h3>Basic Setup</h3><h4>Prepare Your Application</h4><p>Create your main script:</p><pre>// hello.js<br>console.log(`Welcome, ${process.argv[2] || &#39;user&#39;}!`);</pre><h4>Create Configuration</h4><p>Make a build configuration file:</p><pre>// sea-config.json<br>{<br>  &quot;main&quot;: &quot;hello.js&quot;,<br>  &quot;output&quot;: &quot;app-bundle.blob&quot;<br>}</pre><h4>Generate Bundle</h4><p>Run the build command:</p><pre>node --experimental-sea-config sea-config.json</pre><h3>Creating the Executable</h3><h4>Copy Node Binary</h4><p>Make a copy of the Node.js executable:</p><pre>cp $(which node) myapp</pre><h4>Prepare Binary</h4><p>Remove existing signatures (macOS/Windows):</p><pre>codesign --remove-signature myapp  # macOS</pre><h4>Inject Bundle</h4><p>Insert your application bundle:</p><pre>npx postject myapp APP_BUNDLE app-bundle.blob \<br>    --fuse-identifier APP_FUSE_123456789abc</pre><h4>Re-sign Binary</h4><p>Add new signature (macOS/Windows):</p><pre>codesign --sign - myapp  # macOS</pre><h3>Advanced Features</h3><h4>Including Assets</h4><p>Bundle additional files:</p><pre>{<br>  &quot;main&quot;: &quot;app.js&quot;,<br>  &quot;output&quot;: &quot;bundle.blob&quot;,<br>  &quot;assets&quot;: {<br>    &quot;icon.png&quot;: &quot;./assets/icon.png&quot;,<br>    &quot;config.json&quot;: &quot;./config/prod.json&quot;<br>  }<br>}</pre><p>Access assets in your app:</p><pre>const { readAsset } = require(&#39;node:sea&#39;);<br>const icon = readAsset(&#39;icon.png&#39;);</pre><h4>Performance Optimization</h4><p>Enable code caching for faster startup:</p><pre>{<br>  &quot;main&quot;: &quot;app.js&quot;,<br>  &quot;output&quot;: &quot;bundle.blob&quot;,<br>  &quot;useCodeCache&quot;: true<br>}</pre><h4>Limitations</h4><ul><li>Only supports CommonJS modules (not ES modules)</li><li>Requires rebuilding for different platforms</li><li>Large binary size (includes Node.js runtime)</li><li>Limited filesystem access in bundled mode</li></ul><h3>Best Practices</h3><ul><li>Use JavaScript bundlers for complex apps</li><li>Test thoroughly on target platforms</li><li>Consider file size implications</li><li>Document required system permissions</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f95256ac4d37" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>