Search code examples
node.jsmobileintel-xdk

intel XDK directory browsing


I'm trying to get a way to reach and parse all JSON file from a directory, witch inside an Intel Xdk project. All files in my case stored in '/cards' folder of the project. I have tried to reach theme with fs.readdirSync('/cards') method, but that wasn't pointed to the location what I expected, and I haven't got luck with 'intel.xdk.webRoot' path.

With the simulator I've managed to get files, with a trick:

fs.readdirSync(intel.xdk.webRoot.replace('localhost:53862/http-services/emulator-webserver/ripple/userapp/', '')+'cards');

(intel.xdk.webRoot contains absolute path to my '/cards' folder)

and its work like a charm, but it isn't working in any real device what I'd like to build it. I have tried it with iOS7 and Android 4.2 phones.

Please help me to use in a great way the fs.readdirSync() method, or give me some alternate solution.

Thanks and regards,

satire


Solution

  • You can't use nodejs api's on mobile apps. It is a bug that the XDK emulator lets you do it. The bug is fixed in the next release of XDK.

    You could write a node program that scans the directory and then writes out a js file with the contents of the directory. You would run the node script on your laptop before packaging the app in the build tab. The output would look like this: files.js:

    dir = {files: ['file1.txt', 'file2.txt']}

    Then use a script tag to load it:

    And your js can read the dir variable. This assumes that the contents does not change while the app is running.