Giter Site home page Giter Site logo

ambarmendez / ssvm-nodejs-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from second-state/wasmedge-nodejs-starter

0.0 1.0 0.0 437 KB

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

Home Page: https://www.secondstate.io/articles/getting-started-with-rust-function/

JavaScript 17.46% Rust 4.98% Dockerfile 77.56%

ssvm-nodejs-starter's Introduction

Getting started

Build and test

Fork this project to create your own Rust functions in Node.js. Learn more

  • 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 the node node/app.js command to run the application in Node.js.

Use Docker to build and run

$ docker build -t ssvm-nodejs:v1 .
$ docker run -p 3000:3000 --rm -it -v $(pwd):/app ssvm-nodejs:v1
(docker) # cd /app
(docker) # ssvmup build
(docker) # node node/app.js

From a second terminal window, you can test the local server.

$ curl http://localhost:3000/?name=SSVM
hello SSVM

Use VSCode Codespace

SSVM

This project template works with the VS Codespaces online IDE! Code, build, and run directly from inside the browser. No software download or install needed! Check out the high-res screencast.

VS Codespaces runs entirely in your browser and costs around $1 per work day. It is cheaper than a cup of coffee in the office. Alternatively, use locally installed VSCode and Docker, and launch the IDE with your remote git repository.

1 First, open the VS Codespaces web site and login with your Azure account. You can get a free Azure account.

2 Next, create a new Codespace. Put your forked repository into the Git Repository field.

Create a new Codespace

3 Then open the src/lib.rs, node/app.js and Cargo.toml files and see how the Node.js express app calls the Rust function to say hello.

Code in Codespace

4 Click on the Run button on the left panel, and then the Launch Program at the top to build and run the application.

Build and run

The Terminal window at the bottom shows the build progress. It builds the Rust program, and then launches the Node.js app.

Build

The Debug window shows the Node.js server running and waiting for web requests.

Debug

5 Now, you have two choices. You could use the proxy link for 127.0.0.1:3000 to access the running server in a browser.

Browser link

Or, you could open another terminal window in the IDE via the Terminal -> New Terminal menu.

Open Terminal

From the terminal window, you can test the local server.

$ curl http://127.0.0.1:3000/?name=SSVM
hello SSVM

More exercises

Now, you can copy and paste code from this project.

Click on Run to see the build output in Terminal window, and application console output in Debug window.

Try to log into GitHub from the IDE, and use the IDE's GitHub integration features to commit the changes, push the changes back into your forked repository, and perhaps even send us a Pull Request from the IDE!

Read more:

Resources

Brought to you by the Open source dev team at Second State. Follow us on Twitter, Facebook, LinkedIn, YouTube, or Medium

ssvm-nodejs-starter's People

Contributors

alabulei1 avatar juntao avatar vrixyz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.