Skip to content

A template project to run Rust functions in Node.js through the Second State WebAssembly engine.

Notifications You must be signed in to change notification settings

yuanquan8/ssvm-nodejs-starter

 
 

Repository files navigation

Getting started

The Rust functions are in the src directory. You can put high performance workload into Rust functions. The JavaScript functions are in the node directory and they can access the Rust functions.

use docker to run

# or you can exec `./start.sh`
docker run \
-p 3000:3000 \
--rm --it \
-v $(pwd):/app \
secondstate/ssvm-nodejs-starter:v1

and then

cd /app
ssvmup build # build wasm module
npm i # install express
npm start # start server

Now, you can test your local server.

# test express 
curl 0.0.0.0:3000/

# test javascript engine with optimized
curl -H "Content-Type:application/json" -X POST http://0.0.0.0:3000/solve -d '{"engine-select": "javascript", "mode-select": "optimized", "max-number": 10}'

# test javascript engine with brute
curl -H "Content-Type:application/json" -X POST http://0.0.0.0:3000/solve -d '{"engine-select": "javascript", "mode-select": "brute", "max-number": 10}'

# test wasm engine with optimized
curl -H "Content-Type:application/json" -X POST http://0.0.0.0:3000/solve -d '{"engine-select": "wasm", "mode-select": "optimized", "max-number": 10}'

# test wasm engine with brute
curl -H "Content-Type:application/json" -X POST http://0.0.0.0:3000/solve -d '{"engine-select": "wasm", "mode-select": "brute", "max-number": 10}'

You can also visit server by browser

参考资料

学rust,免费拿树莓派

入门文档,在Node.js中调用rust函数

About

A template project to run Rust functions in Node.js through the Second State WebAssembly engine.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 47.6%
  • JavaScript 31.9%
  • Rust 8.7%
  • Dockerfile 8.0%
  • CSS 3.2%
  • Shell 0.6%