overquick v2.0.2
Overquick
Overquick is a hybrid I/O module for JSON files. It reads and writes files on the disk and also saves on the ram to keep good performances. You can easily use encryption to encrypt files with custom keys.
Please go to the Manage Overquick settings
part if you consider using Overquick with APIs which may have exit listener 🥺
Get Started
To get started with Overquick, first, import the OverquickFile
class from the module.
import { OverquickFile } from "overquick";
// or
const { OverquickFile } = require("overquick");
Then creates a new OverquickFile
instance with the path to the file to manage, and, eventually an encryption key.
import { OverquickFile } from "overquick";
const someJSONFile = new OverquickFile("./data/contacts.json");
// with encryption
//(keep in mind that a file used with encryption have to be
// created using Overquick or needs to be crypted using the
// Overquick's encryption tool. See below to learn more.
const someJSONFile = new OverquickFile("./data/contacts.json", {
encryptionKey: "your-key",
});
Now you can edit it using the read
and write
functions of your OverquickFile
instance. Don't bother about autosaving or eventual data loss, Overquick manages it for you!
Setup Encryption on pre-existing files
To encrypt pre-existing files, you must use the translateFile
tool which uses OverquickFile
under the hood to work. You also must use this tool using the node
command line.
There is the output of my own usage of this tool (in the node CLI):
> import {translateFile} from "overquick"
undefined
> translateFile("./tests/data/test.json", "encrypt", "your-key")
[Sat Jan 15 2022 20:06:55 GMT+0100 (heure normale d’Europe centrale), 6] Successfully encrypted the file. Exit the process to save changes.
You can also decrypt an encrypted file just by replacing the "encrypt"
parameter with the "decrypt"
.
Manage Overquick settings
Overquick have many optionnal behaviors, you must manage correctly some of them.
autoManageExit (it's an IMPORTANT one)
Overquick listens to exit-related process events to allow the API to correctly exit without any data loss. But in some cases, like using an express server, these listenings may result in unresponsiveness of the process exit. That's why you need to manually allow Overquick to call theprocess.exit
function or call it by yourself. If you do not take care of this setting, your app may never be shut down. To enable/disable this setting, use the following code:
// overquickSettings is imported from "overquick"
overquickSettings.autoManageExit = true | false;
allowVerbose
Allow Overquick to throw every log into the console. Logs are about operations the API does, you may need them for debugging purposes. Errors are always thrown into the console! To enable/disable this setting, use the following code:
// overquickSettings is imported from "overquick"
overquickSettings.allowVerbose = true | false;