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
- Getting Started - enable
@tsonic/nodejsin a Tsonic project - Importing Modules - what to import from
@tsonic/nodejs/index.jsvs submodules
Modules
- console
- path
- fs
- Buffer
- events
- timers
- process
- os
- util
- assert
- performance
- stream
- readline
- querystring
- zlib
- crypto
- tls
- X509 / Certificate
- dns
- net
- dgram
- child_process
- 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/jsprovides JavaScript runtime APIs (e.g.JSON, JS-styleconsole, timers).@tsonic/nodejsprovides Node-style APIs (e.g.fs,path,crypto,http).
You can enable either or both in a project.