Skip to content

kirencore/kiren

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kiren

A lightweight JavaScript runtime built with Zig and QuickJS.

Kiren is designed for building fast, standalone server applications with minimal footprint. It provides Node.js-compatible APIs while maintaining a small binary size and fast startup time.

Features

  • Fast startup - QuickJS-based engine with minimal overhead
  • Small binary - Single executable under 4MB
  • Bundle to executable - Create standalone apps with kiren bundle
  • HTTP server - Native Zig HTTP server with high throughput
  • WebSocket support - Built-in WebSocket server with rooms
  • SQLite database - Native SQLite for embedded data storage
  • Static file serving - Built-in static middleware with MIME detection
  • Node.js compatibility - Familiar APIs (fs, path, Buffer, etc.)
  • Module system - CommonJS require/exports
  • No dependencies - Self-contained runtime, no npm required

Quick Start

// server.js
const express = require("express");
const app = express();

app.get("/", function(req, res) {
  res.json({ message: "Hello from Kiren!" });
});

app.listen(3000, function() {
  console.log("Server running on http://localhost:3000");
});
kiren server.js

Installation

From Source

Requires Zig 0.14.0 or later.

git clone https://github.com/user/kiren.git
cd kiren
zig build -Doptimize=ReleaseFast

The binary will be available at zig-out/bin/kiren.

Pre-built Binaries

Coming soon.

Usage

# Run a script
kiren script.js

# Run with arguments
kiren server.js --port 8080

API Overview

HTTP Server

Kiren.serve({
  port: 3000,
  fetch: function(req) {
    return new Response(JSON.stringify({ ok: true }), {
      headers: { "Content-Type": "application/json" }
    });
  }
});

WebSocket Server

Kiren.ws({
  port: 8080,
  open: function(ws) {
    Kiren.wsSend(ws, "Welcome!");
  },
  message: function(ws, data) {
    Kiren.wsBroadcast(data);
  }
});

File System

const content = fs.readFileSync("config.json", "utf8");
fs.writeFileSync("output.txt", "Hello World");

Path Utilities

const fullPath = path.join(__dirname, "data", "file.txt");
const ext = path.extname("script.js"); // ".js"

Buffer

const buf = Buffer.from("Hello");
const encoded = buf.toString();

HTTP Client

const response = fetch("https://api.example.com/data");
const data = response.json();

SQLite Database

const db = Kiren.sqlite(':memory:');

db.exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');
db.run('INSERT INTO users (name) VALUES (?)', ['Mert']);

const users = db.query('SELECT * FROM users');
console.log(users); // [{ id: 1, name: 'Mert' }]

db.close();

Static File Serving

const express = require("express");
const app = express();

// Serve static files from ./public directory
app.use(express.static("./public"));

app.listen(3000);

Bundle to Executable

# Create standalone executable
kiren bundle server.js -o server

# Run without kiren installed
./server

For complete API documentation, see docs/API.md.

Compatibility Libraries

Kiren includes drop-in replacements for popular npm packages:

Package Status
express Supported
axios Supported
jsonwebtoken Supported
dotenv Supported
uuid Supported
const express = require("express");
const axios = require("axios");
const jwt = require("jsonwebtoken");
require("dotenv").config();

Project Structure

kiren/
├── src/           # Zig source code
│   ├── main.zig   # Entry point
│   ├── engine.zig # QuickJS bindings
│   └── api/       # JavaScript API implementations
├── lib/           # JavaScript compatibility libraries
├── deps/          # Dependencies (QuickJS, SQLite)
├── tests/         # Test files
├── examples/      # Example applications
└── docs/          # Documentation

Performance

Kiren achieves approximately 20,000 requests/second on a single core for simple JSON responses, comparable to other lightweight runtimes.

Documentation

Contributing

Contributions are welcome. Please read CONTRIBUTING.md before submitting a pull request.

License

MIT License

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published