Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

LLRT Modules

LLRT Modules is a library of rquickjs modules that can be used independantly of LLRT (Low Latency Runtime). They aim to bring to quickjs APIs from Node.js and WinterCG.

LLRT (Low Latency Runtime) is a lightweight JavaScript runtime designed to address the growing demand for fast and efficient Serverless applications.

🛠️ Usage

Each module has a feature flag, they are all enabled by default but if you prefer to can decide which one you need. Check the Compability matrix for the full list.

[dependencies]
llrt_modules = { version = "<version>", features = [
	"<feature>",
], default-features = false }

Once you have enable a module, you can import it in your runtime.

[!NOTE] Some modules currently require that you call an init function before they evaluated.

use llrt_modules::buffer;
use rquickjs::{AsyncRuntime, AsyncContext, async_with, Error, Module};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let runtime = AsyncRuntime::new()?;
    let context = AsyncContext::full(&runtime).await?;

    async_with!(context => |ctx| {
        buffer::init(ctx)?;
        let (_module, module_eval) = Module::evaluate_def::<buffer::BufferModule, _>(ctx.clone(), "buffer")?;
        module_eval.into_future().await?;

        ctx.eval(
          r#"
          import { Buffer } from "buffer";
          Buffer.alloc(10);
          "#,
        )?;

        Ok::<_, Error>(())
    })
    .await?;

    Ok(())
}

Compatibility matrix

[!NOTE] Only a fraction of the Node.js APIs are supported. Below is a high level overview of partially supported APIs and modules.

Node.js LLRT Modules Feature
buffer ✔︎ ✔︎️ buffer
child process ✔︎ ⚠️ child-process
events ✔︎ ⚠️ events
exceptions ✔︎ ⚠️ exceptions
fs/promises ✔︎ ⚠️ fs
fs ✔︎ ⚠️ fs
navigator ✔︎ ⚠️ navigator
net ✔︎ ⚠️ net
os ✔︎ ⚠️ os
path ✔︎ ✔︎ path
perf hooks ✔︎ ⚠️ perf-hooks
process ✔︎ ✔︎ process
zlib ✔︎ ⚠️ zlib
Other modules ✔︎ ✘ N/A

⚠️ = partially supported ⏱ = planned partial support * = Not native ** = Use fetch instead