Skip to content

tsoniclang/nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

113 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@tsonic/nodejs

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.

Prerequisites

Quick Start

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 dev

Existing project

npx --yes tsonic@latest add npm @tsonic/nodejs

Versioning

This repo is versioned by runtime major:

  • 10versions/10/ → npm: @tsonic/nodejs@10.x

When publishing, run: npm publish versions/10 --access public

Core Modules (what you get)

  • fs, path, events, crypto, process
  • http (separate module entrypoint)

Usage

File System

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!");

Path Operations

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);

Events

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

class MyEmitter extends EventEmitter {}
const emitter = new MyEmitter();
emitter.on("data", (chunk) => console.log(chunk));

Crypto

import { crypto } from "@tsonic/nodejs/index.js";

const hash = crypto.createHash("sha256").update("hello").digest("hex");
void hash;

Process

import { process } from "@tsonic/nodejs/index.js";

const cwd = process.cwd();
void cwd;

HTTP

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

Imports (important)

This is an ESM package. Import from the explicit entrypoints:

  • @tsonic/nodejs/index.js for most Node-style APIs (fs, path, crypto, process, …)
  • submodules like @tsonic/nodejs/nodejs.Http.js for separately emitted namespaces

Node’s built-in specifiers like node:fs are not supported here.

Relationship to @tsonic/js

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

Documentation

Naming Conventions

  • @tsonic/nodejs intentionally uses Node/JS-style naming (camelCase members).

Development

See __build/ for regeneration scripts.

License

MIT

About

d.ts files for Node CLR compat

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages