Installing WebAssembly locally

Learn how to install WebAssembly locally to solve Exercism's exercises on your own machine

This track relies on Node.js throughout to provide a runtime for WebAssembly. This means that we assume all execution of JavaScript on your computer will happen using Node.js.

Track Requirements

Many machines come pre-installed with Node.js or might have been installed previously, or as a dependency. So before we do anything, we should check if it's already installed:

  1. Open up a terminal (Terminal, cmd, Powershell, bash, ...)
  2. Run node -v

If Node.js is installed, a version is displayed. Write this version down. If Node.js is not installed, an error will be written out. Usually, something along the lines of 'node' is not recognised.


If Node.js is pre-installed

Browse to the Node.js website. It will display two versions (if it detects your OS. Otherwise, select your OS first). If your node -v version matches one of these, you're good. If it doesn't, we recommend that you use Node.js LTS. If you're worried upgrading might break something on your system, you can continue as if everything is fine; we might not be able to provide support when something unexpected happens though.

If Node.js is not installed

There are a couple of ways to install Node.js:

Both options support Windows, macOS, and Linux. If you don't know what to do, using an installer is the easiest.

  • We recommend using the LTS version. This is also indicated as recommended on the Node.js website "for most users".
  • Follow the instructions on the webpage and/or during the installer and install Node.js.

Testing the installation

After the installer is done, or the package manager has completed, or the binary has been copied and the instructions have been followed, it's good to test if everything is alright.

  1. Open up a terminal (Terminal, cmd, Powershell, bash, ...)
  2. Run node -v

The version should match the one on the website.

Note: It is important to open a new terminal window. Any open terminal windows might not have been refreshed after the installation completed. This means that the open terminals don't know that a new program was installed.

Help: 'node' is not recognised

If you've used the official installer, your PATH should have been automatically configured, but if your shell has trouble locating your globally installed modules — or if you build Node.js from source — update your PATH to include the npm binaries.

On macOS and Linux you may accomplish this by adding the following to either ~/.bash_profile or ~/.zshrc:

export PATH=/usr/local/share/npm/bin:$PATH

On Windows open the start menu and search for "environment variables". You'll need to edit the PATH entry and add the path to the npm binaries here. Usually, these are found at C:\Program Files\nodejs. If you browse here with your File Explorer, you should find node.exe, npm.bat and npx.bat.

Close any open terminals and open a new one.

Assignment Requirements

Please follow these instructions to download the Exercism CLI for your OS.

Once the CLI is set up and configured, download the first exercise - hello-world:

exercism download --exercise=hello-world --track=wasm

Each assignment then needs some tools to run the tests. They can be installed running this command within each assignment directory:

npm install

Help: '<package>' is missing / cannot be found

If you see this after upgrading your exercise, welcome to npm 7. Delete node_modules and package-lock.json and re-run the command to resolve this.

If you're concerned about disk space and are okay installing another tool, take a look at pnpm, which ensure only one copy of each package-version is ever installed on disk. In this case, run pnpm install instead of npm install, and everything should work as expected.

But what is npm and why does this work?

You don't need this information to complete the JavaScript track, but if you're eager to understand what just happened, the following paragraphs are for you:

This works because npm is a package manager that comes bundled with Node.js, which has been installed per the steps above. The npm command looks for a package.json file, which is present in each assignment folder. This file lists the "dependencies" above, which are then downloaded by npm and placed into the node_modules folder.

The scripts in the package.json use the binaries from the local node_modules folder, and it's these scripts that are used to run the tests, as listed in the exercise description.