Node-style APIs for Tsonic.
This package is part of Tsonic: https://tsonic.org.
Use @tsonic/nodejs when you want Node-like modules (fs, path, events, crypto, process, http, …) while still compiling to a native binary with tsonic.
- Install the .NET 10 SDK (required by Tsonic): https://dotnet.microsoft.com/download
- Verify:
dotnet --version
mkdir my-app && cd my-app
npx --yes tsonic@latest init
npx --yes tsonic@latest add npm @tsonic/nodejs
# Replace the default App.ts with a Node.js-style example
cat > packages/my-app/src/App.ts <<'EOF'
import { console, path } from "@tsonic/nodejs/index.js";
export function main(): void {
console.log(path.posix.join("a", "b", "c"));
}
EOF
npm run devnpx --yes tsonic@latest add npm @tsonic/nodejsThis repo is versioned by runtime major:
10→versions/10/→ npm:@tsonic/nodejs@10.x
When publishing, run: npm publish versions/10 --access public
fs,path,events,crypto,processhttp(separate module entrypoint)
import { fs } from "@tsonic/nodejs/index.js";
// Read file
const content = fs.readFileSync("./package.json", "utf-8");
// Write file
fs.writeFileSync("./output.txt", "Hello from Tsonic!");import { path } from "@tsonic/nodejs/index.js";
const fullPath = path.join("config", "settings.json");
const ext = path.extname(fullPath); // ".json"
const dir = path.dirname(fullPath);import { EventEmitter, console } from "@tsonic/nodejs/index.js";
class MyEmitter extends EventEmitter {}
const emitter = new MyEmitter();
emitter.on("data", (chunk) => console.log(chunk));import { crypto } from "@tsonic/nodejs/index.js";
const hash = crypto.createHash("sha256").update("hello").digest("hex");
void hash;import { process } from "@tsonic/nodejs/index.js";
const cwd = process.cwd();
void cwd;import { http } from "@tsonic/nodejs/nodejs.Http.js";This is an ESM package. Import from the explicit entrypoints:
@tsonic/nodejs/index.jsfor most Node-style APIs (fs,path,crypto,process, …)- submodules like
@tsonic/nodejs/nodejs.Http.jsfor separately emitted namespaces
Node’s built-in specifiers like node:fs are not supported here.
@tsonic/jsprovides JavaScript runtime APIs (JS-styleconsole,JSON, timers, etc.)@tsonic/nodejsprovides Node-style modules (fs,path,crypto,http, etc.)
- docs/getting-started.md
- docs/imports.md
- Module docs: fs, path, crypto, http, events, process
- https://tsonic.org/nodejs/
@tsonic/nodejsintentionally uses Node/JS-style naming (camelCase members).
See __build/ for regeneration scripts.
MIT