Tsonic GitHub
Edit on GitHub

Node.js Compatibility (@tsonic/nodejs)

Tsonic targets the .NET BCL by default. If you want Node-style APIs (like fs, path, crypto, net, process, etc.), use @tsonic/nodejs.

This is not Node.js itself, and it is not a byte-for-byte clone of the Node standard library. It is a curated, Node-inspired API surface implemented on .NET for Tsonic projects.

Table of Contents

Getting Started

  1. Getting Started - enable @tsonic/nodejs in a Tsonic project
  2. Importing Modules - what to import from @tsonic/nodejs/index.js vs submodules

Modules

  1. console
  2. path
  3. fs
  4. Buffer
  5. events
  6. timers
  7. process
  8. os
  9. util
  10. assert
  11. performance
  12. stream
  13. readline
  14. querystring
  15. zlib
  16. crypto
  17. tls
  18. X509 / Certificate
  19. dns
  20. net
  21. dgram
  22. child_process
  23. http (separate submodule)

Overview

In Tsonic projects you import Node-style APIs from @tsonic/nodejs/index.js:

import { console, fs, path } from "@tsonic/nodejs/index.js";

export function main(): void {
  console.log(path.join("a", "b", "c"));
  const text = fs.readFileSync("./README.md", "utf-8");
  console.log(text);
}

Some namespaces are emitted as separate ESM entry points (for example nodejs.Http), and you import those via a subpath:

import { http } from "@tsonic/nodejs/nodejs.Http.js";

Relationship to @tsonic/js

  • @tsonic/js provides JavaScript runtime APIs (e.g. JSON, JS-style console, timers).
  • @tsonic/nodejs provides Node-style APIs (e.g. fs, path, crypto, http).

You can enable either or both in a project.