Module Tutorial

Can someone give me a simple example such as:

Using the module to generate a random number.

I went through the backend function and I am still clueless…

Backend functions are a component of modules but all modules don’t need backend functions. Backend functions are useful for things that you might want to do in a serverless environment away from the client side.

Modules are a way to re-use code, and work similarly to npm modules where you define your module and can then import it when creating your experience. Without backend functions your module code runs on the client which should be fine for a majority of use cases.

Here’s an example where the min and max values of the random generation are driven from config values on the module. Config values are editable for the developer using the module, not the end user.

// module.js is the main entry point for your 8th Wall module.
// Code here will execute before the project is loaded.

import {subscribe} from 'config'

let min = 0
let max = 1

subscribe((config) => {
  console.log('My Module Printed This!', config)

  min = config.min
  max = config.max
})

function generateRandomNumber() {
  return Math.random() * (max - min) + min
}

export {
  generateRandomNumber,
}

I followed the documentation and received this error.
What am I doing wrong?

The entry path should point to the file containing your code. For instance, you can create a file named index.js (or any name you prefer) and set your backend’s entry path to ‘index.js’.

Take a look at the backend function template here:

https://www.8thwall.com/8thwall/modules/bfn-studio/code/