https://github.com/neo-ciber94/rust-wasm-nodejs
A sample app to call rust-wasm from nodejs
https://github.com/neo-ciber94/rust-wasm-nodejs
Last synced: 4 months ago
JSON representation
A sample app to call rust-wasm from nodejs
- Host: GitHub
- URL: https://github.com/neo-ciber94/rust-wasm-nodejs
- Owner: Neo-Ciber94
- Created: 2023-04-27T04:50:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-27T05:03:05.000Z (over 2 years ago)
- Last Synced: 2025-01-06T17:47:05.507Z (9 months ago)
- Language: Rust
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Calling Rust from NodeJS
This is a example for calling **wasm** `Rust` function from `NodeJS`.
## Requirements
- **node**
-
- **wasm-bindgen-cli**
-
- **cargo make (optional, can be run manually)**
-## How to run?
1. Install the node dependencies
```bash
npm install
```2. Build the wasm
```bash
cargo make build
```3. Starts the nodejs server
```bash
npm run start
```> After that **GET** or **POST** to the `http://localhost:3000`
## Manual run
After installing the node dependencies:
1. Build to wasm32
- `cargo build --target wasm32-unknown-unknown`
2. Bundle the wasm
- `wasm-bindgen --typescript --target nodejs --out-dir src/pkg target/wasm32-unknown-unknown/debug/rust_wasm_nodejs.wasm`
3. Starts the node server
- `npx tsx src/index.ts`