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.
- JavaScript runtime built on V8 engine
- File system operations
- Built-in HTTP server
- Console API implementation
- Timer functions (setTimeout, setInterval)
- Go 1.23 or higher
- GCC (for v8go compilation)
Note: Windows is not supported as v8go dropped Windows support
- Clone the repository:
git clone https://github.com/Kumneger0/Tibebjs.git
cd Tibebjs- Install dependencies:
go mod downloadgo build -o tibebjsgo build -o tibebjsNote: Due to CGO dependencies (v8go), cross-compilation requires additional setup. It's recommended to build on the target platform directly.
Execute JavaScript files:
./tibebjs path/to/your/script.jspkg/runtime/: Core runtime implementationeventloop/: Event loop and async operationsconsole/: Console API implementationtimer/: Timer functionalitynet/: Network operationsfs/: File system operationsfetch/: HTTP client implementationutils/: Utility functions
globals/: Global objects and bindings
// 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');// 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);- Roll your own JavaScript runtime - Original Deno blog post (which is in Rust)
- v8go Documentation - Go V8 bindings documentation
Feel free to submit a Pull Request or open an issue for discussion.
This project is licensed under the MIT License - see the LICENSE file for details.