Skip to content

Kumneger0/Tibebjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TibebJS

License: MIT

A JavaScript runtime experiment inspired by Roll your own JavaScript runtime - (which is in Rust). This is just an experiment how JavaScript runtimes work and is not intended for production use.

Features

  • JavaScript runtime built on V8 engine
  • File system operations
  • Built-in HTTP server
  • Console API implementation
  • Timer functions (setTimeout, setInterval)

Prerequisites

  • Go 1.23 or higher
  • GCC (for v8go compilation)

Note: Windows is not supported as v8go dropped Windows support

Getting Started

  1. Clone the repository:
git clone https://github.com/Kumneger0/Tibebjs.git
cd Tibebjs
  1. Install dependencies:
go mod download

Building

On Linux

go build -o tibebjs

On macOS

go build -o tibebjs

Note: Due to CGO dependencies (v8go), cross-compilation requires additional setup. It's recommended to build on the target platform directly.

Running

Execute JavaScript files:

./tibebjs path/to/your/script.js

Project Structure

  • pkg/
    • runtime/: Core runtime implementation
    • eventloop/: Event loop and async operations
    • console/: Console API implementation
    • timer/: Timer functionality
    • net/: Network operations
    • fs/: File system operations
    • fetch/: HTTP client implementation
    • utils/: Utility functions
  • globals/: Global objects and bindings

Examples

File System Operations

// Write to file
await Tibeb.writeFile('file.txt', 'content');

// Read from file
const content = await Tibeb.readFile('file.txt');

// Remove file
await Tibeb.rmFile('file.txt');

// Rename file
await Tibeb.renameFile('old.txt', 'new.txt');

HTTP Server

// Create a simple HTTP server
Tibeb.serve((request) => {
  // Request object contains url, method, and headers
  const response = {
    url: request.url,        // URL path of the request
    method: request.method,  // HTTP method (GET, POST, etc.)
    headers: request.headers // Request headers
  };
  
  return response(JSON.stringify(response), {
    status: 200,
    headers: { "Content-Type": "application/json" }
  });
}, 3000); // Listen on port 3000

// Example with routing
Tibeb.serve((request) => {
  switch(request.url) {
    case "/":
      return response(JSON.stringify({ 
        path: "home",
        method: request.method,
        headers: request.headers 
      }), {
        status: 200,
        headers: { "Content-Type": "application/json" }
      });
      
    case "/api":
      return response(JSON.stringify({ 
        path: "api",
        method: request.method,
        headers: request.headers 
      }), {
        status: 200,
        headers: { "Content-Type": "application/json" }
      });
      
    default:
      return response(JSON.stringify({ 
        error: "Not Found",
        path: request.url,
        method: request.method 
      }), {
        status: 404,
        headers: { "Content-Type": "application/json" }
      });
  }
}, 3000);

Resources

Contributing

Feel free to submit a Pull Request or open an issue for discussion.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A lightweight and minimal JavaScript runtime

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages