Seems like everyone who's written a Node app has also written a JSON file storage module. I guess I'm no exception. Here's my rationale for publishing jdrop:
const jdrop =path: 'data'autocatch: true;let data =post:body: 'hello';// save datajdrop;// update part of a filejdrop;// get datajdrop;// delete part of a filejdrop;// delete a filejdrop;
When you initialize jdrop, you can pass a config object with two optional settings.
path is the directory in which to store JSON files. The keys you use to access files are paths relative to this directory. The default path is
autocatch controlls error handling behavior. The default behavior uses a promise rejection, which you can handle thusly:
If you set
true, jdrop will no longer reject promises. Instead, it will log the error and end the process with exit code 1.
Alternatively, you can supply a function to the
autocatch setting. This function will be passed any error objects that arise. You can use this to send an error to the client without crashing.