Node Bridge

Simple rust script to achieve a bridge between node.js and rust. Use with the npm package rust-bridge.

Installation

Add the following line to your Cargo.toml under [dependencies]

toml node_bridge = "0.1.0"

Node.js installation: bash $ npm install rust-bridge

Usage/Examples

```rust

[tokio::main]

async fn main() { nodebridge::register(vec![("add", add), ("findlonger", find_longer)]).await; // Results if the bridge closes. }

fn add(params: Vec<&str>) -> String { (params[0].parse::().unwrap() + params[1].parse::().unwrap()).to_string() }

fn findlonger(params: Vec<&str>) -> String { if params[0].len() > params[1].len() { return params[0].tostring(); } params[1].to_string() }

Handling in node.js: javascript import RustBridge from "rust-bridge";

const bridge = new RustBridge("/path/to/rust-executable"); await bridge.init();

console.log(await bridge.add(1,2)); // "3"

console.log(await bridge.find_longer("long", "longer")); // "longer"

bridge.close(); // true ```

Contributing

Contributions are always welcome!