0 Favourites

Work with the filesystem API

  • Hello, this is my first post

    This is the thing. I want to implement my own directory reader. I've been checking the AJAX and Nodewebkit plugin and both use the "fs" variable. I'm guessing that "fs" stands for "filesystem", but I'm not sure about that. I can't find nothing about that in the manual and when I try to use something like those plugins do, it always fails with a "require is not defined" error message.

    This is the code both plugins use :

    		if (isNodeWebkit)
    		{
    			path = require("path");
    			fs = require("fs");
    			nw_appfolder = path["dirname"](process["execPath"]) + "\\";
    		}
    [/code:elqky6eh]
    
    But I don't know where is defined the 'require' function, neither the "fs" or "path". If I try with my plugin to print those values it always throws that error.
    
    Is there anyway to work with the filesystem api, or do I have to create an instance of it by myself? Because I can't find nothing similar to that in the plugins.
    
    Thanks in advance.
  • Yes, fs stands for filesystem, it is an implementation from nodejs's fs module, you can read more about it here:

    http://nodejs.org/api/fs.html

    the require function comes with node, read more about it here:

    http://nodejs.org/api/modules.html

    Are you previewing your project in nodewebkit? because fs (and require and node stuff) is not available inside the browser!

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Actually I'm previewing in Chrome. My idea is trying to implement my own directory reader. I thought that the filesystem variable was a C2 thing, but now you let me know it's part of nodewebkit.

    I'll see it later with a little more time.

    Thanks for your answer, it really helped me out to understand how it works.

  • Another question...

    According to what you said, if I'm not using Nodewebkit the filesystem api will not work (that's what I understood). In other words, if I try to create a HTML5 application able to read a directory (the project directory) I will have to use the nodewebkit? Is there a chance to just preview in nodewebkit and then add the node.js library to the application and run it in every browser?

    Thanks for your answer in advance, again.

    PS: I've been checking if I can give you reputation points, but I can't find the option. Perhaps is earned automatically by answering a post, anyway, you deserve it. Thanks.

  • Unfortunately, nope, you can't get the "real" fs (and any other node stuff) inside a normal chrome browser.

    The magic of node-webkit is in the combination of node.js, and chromium browser (former webkit, currently blink), hence the node-webkit. check the git project hosted on github for more info on nodewebkit.

    You could check out the awesome browserify-fs project (https://github.com/mafintosh/browserify-fs) it has the "fs" module implementation for chrome, but it does not give you access to the whole system, it just emulates "fs" inside leveldb so you cannot read some file on c:/documents/whatever , it just stores a file inside local storage. (but you can store a pdf using browserify-fs, or a .doc, or a .capx file, if you're into it)

    I didnt use the browserify-fs project yet, so you're on your own there, but it might be useful, depending on your requirements.

    edit: looks like browserify doesent support fs check out: www.browserify.org

  • Oh, well, that's good to know. I'll check everything you said.

    Thanks again for your help.

    Have a nice day

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)