I am creating a complex object dynamically with nodejs in an effort to write this data to a file for use as a frontend utility library.
Is there any way that I can read/write this object to a file?
Methods I am aware of that fall short:
JSON.stringify: need to output methodsjsDump : end up with
[code]blocks for function bodytrying to create a new
Bufferfrom the objectFunction.prototype.toString
I'm beginning to think that this is just not possible. Can anyone prove me wrong?
Note: As easy as it is to just read/concat/write files together with workable code for the browser, I would also like to be able to use this as an npm package. The library is set up in a fashion where each bit of reusable code is living in its own file. A build tool allows you to select which files you would like to include in the end result. The complex object I speak of is actually just a global namespace for all of the resulting functionality.
Edit for clarity
Resulting object stored in memory
var obj = {
foo: 'a string',
reg: /\s+/,
num: 100,
fart: function (name) {
return name + ' farted and it sounded like pffftt';
},
Fart: function (sound) {
this.sound = sound;
}
};
And then you write that object character-for-character in a file for use in a browser.