Skip to content

Options

All .read(), .write(), and post() methods take an optional Options parameter. It is an object containing a set of values, overrides that can be utilized to change how prefsdb.com works.


timeout

Request / query timeout. Default value is 20000 (20 seconds).

{
    timeout: 30000
}

This will make a request to read data give up after 10 seconds.

prefs_us.read( { timeout: 10000 } )


onsuccess

Function to be called when data is received. Default value is null: a Promise will be returned.

{
    onsuccess: (response) => {
        data = response.value;
    }
}
The response will contain either value or values fields. Which one will be set will depend whether a query returns a single value or multiple values. The number of values returned will be reported in count field.


onerror

Function to be called when the call failed or resulted in an error. Default value is null. If not provided error will not be surfaced and opportunity to respond to errors will be missed.

{
    onerror: (error) => {
        alert(error.message);
    }
}
Error object most likely will look like this:
{
    success: false, 
    status: "error", 
    ts: "2026-05-18 19:22:48", 
    error: "400 Bad Request", 
    message: "Missing API key"
}

Options example

    .key("username").write(stats, {
        onsuccess: (response)=>{
            console.log("Data saved ok");
        },
        onerror: (error)=>{
            console.log("error: %s", error.message);
        },
        timeout: 60
    });