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?
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 ();
}
}
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: