[SOLVED] JavaScript modules

Posted on
  • How can I write a JavaScript module that can be installed on the Bangle and then required from another app? Is that possible?

  • I think the answer is provided here: https://www.espruino.com/Modules

  • Yep, the easiest way is using: https://www.espruino.com/Modules#from-stĀ­orage

    require("Storage").write("answer",`
    exports.get = function() {
      return 42;
    };`)
    print(require("answer").get());
    // prints 42
    

    Rather than using require("Storage").write you can use the down-arrow by the Web IDE's Upload button to choose Storage and then the module filename you want - then you can upload directly.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

[SOLVED] JavaScript modules

Posted by Avatar for 4thex @4thex

Actions