Pkg: How to access files without including into executable

Created on 10 May 2017  路  4Comments  路  Source: vercel/pkg

I'm trying to do a read / write on .txt files using fs. However, it seems I have to include them into executable. Is it possible for executable to access .txt files within the same directory without including them as assets?

Most helpful comment

@ganeshkbhat Hi

If you want to access a file outside of the snapshot filesystem, use process.cwd() instead of __dirname.

This is also mentioned in the pkg docs:

On the other hand, in order to access real file system (pick up a user's JS plugin or list user's directory) you should take process.cwd() or path.dirname(process.execPath).

All 4 comments

I figured out.

@telunc can you share the same as code example. I have been trying to do it as well.

@ganeshkbhat Hi

If you want to access a file outside of the snapshot filesystem, use process.cwd() instead of __dirname.

This is also mentioned in the pkg docs:

On the other hand, in order to access real file system (pick up a user's JS plugin or list user's directory) you should take process.cwd() or path.dirname(process.execPath).

this is the block i created and it is still not working @ganeshkbhat

  if (process.env.DB_POSTGRES === undefined) {
        log.bright.white ('Try in find the properties file for configurations');

        const options = {
            path: true,
            reviver: function (key, value, section) {
                if (this.isSection) return this.assert ();
                //If the key begins with _ the property is not added
                if (key[0] === "_") return;
                return this.assert ();
            }
        };
        const path_set = process.cwd();
            //path.dirname (process.execPath);
        const file_name = 'application.properties';
        const pf2 = path.join (path_set, file_name);

        require ('properties').parse (pf2, options, function (error, p) {
            if (error) return console.error (error);
            console.log (p);
            process.env = p;
            exe ();
        });
    } else {
        exe ();
    }
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ydubois-fr picture ydubois-fr  路  4Comments

serzhiio picture serzhiio  路  3Comments

Nisthar picture Nisthar  路  4Comments

bergheim picture bergheim  路  3Comments

Araknos picture Araknos  路  4Comments