Loading modules from SD Card

Posted on
  • Hi.
    My board is a HYSTM32_24_ve. When I try to load a my own module saved in SD, Espruino Web IDE tells "Module xxx not found". What can be a reason of this situation?

    When I look the SD by "require('fs').readdir()", the Espruino shows me its correct contents.
    When I look the directory 'node_modules' by "require('fs').readdir('node_modules')",­ it shows me the file 'xxx.js', that I need.
    But when I try type a "require('xxxx')", it returns me "Module xxx not found".

  • Which version of Espruino are you using? the most recent one?

  • By the way, you know that if you're using the Web IDE it'll load modules automatically without needing the SD card?

  • I have the latest version of Espruino - 1v65.

    Yes, I know this. But I haven't always an internet connection. And I'd like to save Espruino site modules to SD and to have they on hand anytime. Moreover it's comfortable to call own subroutines, that you use often, from module, and you needn't insert they manually every time in your new project.

  • What filename/module name did you use? I just tried the following and it worked fine:

    In node_modules/foo.js

    exports.foo = "Hello World";
    

    And in Espruino's console:

    >require("foo")
    ={
          "foo":"Hello World"
        }
    
  • The problem is that you haven't actually written a proper module. Try:

    exports.toggle1 = function() {
    ...
    }
    etc...
    
  • Really. It was a reason. Now all works properly.
    Thanks.

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

Loading modules from SD Card

Posted by Avatar for Uhv @Uhv

Actions