• I’m writing a project that uses WiFi and I’d like to publish it on github. However, I don’t want to publish my WiFi credentials. The way I’d usually solve this is by creating a settings file and putting it in .gitignore. In this case it would look something like this:

    var WiFiCredentials = require('./wifi-credentials.js');
    

    I also wrote some modules and I’d prefer to publish them alongside with the main project file rather than separately.

    Is there any way I can require a local module not from the modules folder?

  • The simplest way I can think of doing it is to require("http://localhost/credentials") - you could set up a webserver on your own computer for it. You can even set to server up to only accept local connections.

    I'd toyed with the idea of adding a 'macros' section into the IDE so you could set up constants that would get replaced in your code before it was uploaded. Not sure if that'd be any help?

  • ... or I'd just stick it in the modules directory. That would be most simple :)

  • The idea is to make it simple for those who clone the GitHub repo. If require worked the way I want it they would just run the project without the need to clone the modules separately. (I also don't want to publish those modules separately because they are very custom and made for a particular project)

    The local server is, of course, too overcomplicated for this purpose.

  • Well, the Web IDE is all Open Source, so it wouldn't be too hard for you to change the relevant code and issue a pull request if you wanted.

  • Will look into it, thanks!

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

Any way I can `require` a file from the project’s folder?

Posted by Avatar for wilddeer @wilddeer

Actions