• Espruino looks at different places for modules at code upload time when using just the name as string literal (single or double quoted, but not as variable):

    1. built in - no upload needed. For access, you still need to require() the module
    2. http://www.espruino.com/modules/ - from Espruino's official modules repository
    3. modules folder from project sandbox folder specified

    Web IDE code upload can also handle a url in (as string literal): the code will be pulled from the given url and uploaded to Espruino board (board with Espruino firmware / standalone operating system).

    Espruino executes the uploaded code - it is JavaScript after all - and stores the result in the modules cache, from where it is then pulled at runtime when the require() is actually executed. Again, at that moment it checks wether it is a (binary / firmware / operating system) built-in module, a cached module, or it can be found on a mounted SD card / file system. At runtime / on execution, require() does not care if the provided string argument is a literal or a variable. This allows to dynamically require a module at runtime by a variable, but as said, the module has to found, otherwise an error / exception is thrown.

    To make the code example to work, it may be good enough to define the sandbox project modules folder in the Web IDE and save the UDP module as UDP.js (or minified as UDP.min.js) in that folder. Minifying can be done on googles (JS) closure compiler Web page.

    For a bit more what is going on uploading code, saving code on Espruino board, repowering Espruino boards, etc. can found in the conversation titled simple explanation how to save code that espruino run on start?.

    I hope this helps getting you going...

About

Avatar for allObjects @allObjects started