Search code examples
javaservletsringojs

How do I get the real filesystem path from within RingoJS webapp?


If I manage to get ServletContext object from java's HttpRequest, I'd manage to accomplish this, but I couldn't find out how to access these objects from Ringo wrappers.

This is needed to create a file inside the webapp with some saved information. The relative paths correspond to different absolute paths in different enviroment, so we need to find the webapp absolute filesystem path.


Solution

  • It looks like you can use module.resolve() to get the directory the current module is in. I assume you could just append the module name afterwards, like so:

    var fs = require('fs');
    
    var path = fs.join(module.resolve(), 'module-name.js');
    

    I'm trying to find out a better way - no one on the IRC seems to respond, but I'll update this answer if I succeed.

    EDIT #1: I can't seem to find a simpler way, and it doesn't look like Rhino or ECMAScript 5 supports this natively.