$ git clone https://github.com/second-state/ssvm-nodejs-starter $ cd ssvm-nodejs-starter
Pull a Docker image with the prerequisite software stack.
$ docker pull secondstate/ssvm-nodejs-starter:v1
Next run the Docker image, and mount your local workspace. This way, you can run software inside the Docker container against your local files. You can also map ports from Docker to the local machine so that you can test web applications.
$ docker run -p 3000:3000 --rm -it -v $(pwd):/app secondstate/ssvm-nodejs-starter:v1 (docker) $ cd /app
That's it. You can now build and deploy software from the
(docker) # command line. All changes to your code will be saved in your local files regardless whether you stop or delete the Docker container.
Of course, not everyone wants to use Docker. In the rest of the article, we will walk through setps for a manual setup in a fresh Ubuntu Server 20.04 distribution. The whole system takes 10 minutes to set up. We will install Rust, Node.js, the Second State WebAssembly VM (SSVM), and the ssvmup compiler tool.
Setup the Operating System
We recommend you use the Ubuntu 20.04 LTS or later. The SSVM depends on the latest version of the
libstdc++ library, which is already installed on Ubuntu 20.04. If you are using another Linux distribution, please make sure that
GLIBCXX >= 3.4.28 or upgrade as needed.
Then, use the commands below to bring your operating system up to date with the latest developer tools.
$ sudo apt-get update $ sudo apt-get -y upgrade $ sudo apt install build-essential libboost-all-dev $ sudo apt install curl wget git vim pkg-config libssl-dev // Optional
Installing Rust on your Linux machine is very easy. Just two commands.
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh $ source $HOME/.cargo/env
For more options on installing Rust on different systems, please refer to the official Rust documentation.
The best way to install Node.js on Linux is through the NVM tool. NVM allows you to use the latest Node.js, and change easily when you need to test your code on a different version of Node.js.
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash $ export NVM_DIR="$HOME/.nvm" $ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" $ [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" $ nvm install v12.18.3 $ nvm use v12.18.3
For more options on installing Node.js on different systems, please refer to the official Node.js documentation.
Second State VM
The Second State Virtual Machine (SSVM) is an open source WebAssembly runtime optimized for server-side applications. Use the following commands to install it as a Node.js module.
$ npm install ssvm
The ssvmup compiler toolchain
The ssvmup tool provides an easy command to compile Rust functions into WebAssembly and it automatically generates Node.js and SSVM integration code. Since you already have Node.js installed, this just requires one command.
$ npm install -g ssvmup # Append --unsafe-perm if permission denied
Now you have all the tools, get started with a hello world example!