WinXP: how can I require() some locally held modules?

Posted on
  • I experiment with the single-button-combination-lock example.
    But I want to hide the code array in an external file and use it with require:

    var code_code = require('combination_lock_code_code');
    // var code = [3,1,2];
    var code = code_code.code;

    From the documentation I learned that I have to change the communication settings, so I entered:

    But I got some:
    ERROR: SD card must be setup with E.connectSDCard first
    WARNING: Module "combination_lock_code_code" not found

    So: how can I use require to load some local module?
    TIA, Uli

    Update: just found where to put it: the MODULES subdirectory on the Project Path.

  • Hi Uli,

    Due to some security precautions on Chrome, you can't use file:// in the Web IDE - you'll probably want to put the URL back to the default or no existing modules will work.

    To do what you want, go to the Project heading under Settings, then Select Directory for Sandbox. Once that is done, there'll be a modules subdirectory put under the directory you selected, and you can put any modules you want into that.

  • @Gordon thanks for the reply.

    So when I need to work offline with the IDE, I just have to transfer all the modules from your URL to the local modules folder?

    I am pretty aware that's not the professional way to do, but when experimenting with the barePICO (just to learn javascript on a coding night) there may not be a WIFI everywhere.

  • Yes, that should work fine... Otherwise you could set up a local web server, and then you could change the URL under Communications as you were doing previously.

  • Settings > Project > Select Directory for Sandbox

    Unfortunately, this does not work when a module requires another module, for example:

    // projects/hello_world.js
    // modules/hello.js
    var world = require('world'); = function(){ print('Hello ' + world.get()); };
    // modules/world.js
    exports.get = function(){ return 'world'; };

    In the code above - module 'hello' requires module 'world', which does not seem to work, regardless of where you put 'world' and how you include it (as separate module - under 'modules/world.js', or in a subfolder - like 'modules/hello/world.js').

    As already described above, current workaround is to serve modules from a server of your choice:

    • setup your server to serve static files from the 'modules' folder;
    • Web IDE > Settings > Communications > Module URL - put URL of the 'modules' folder (e.g. "http://localhost:9080/modules")

    Am I doing it wrong, or are there plans to enable including local nested modules in the future?
    (Web IDE v0.68.6)

  • Hmm, that does sound like a bug in the project handling code. I filed an issue on it at¬≠DE/issues/186

    Any ideas what might be up @JumJum? I think you did that code originally?

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

WinXP: how can I require() some locally held modules?

Posted by Avatar for UliMerkel @UliMerkel