Skip to main content

Initialization

The function on this page is exported from the pixstore/backend entrypoint:

import { initPixstoreBackend } from 'pixstore/backend'

initPixstoreBackend

Initializes the Pixstore backend module with optional runtime configuration.

This is the main entry point to set up Pixstore on the server side.

It configures the internal state, prepares the metadata database, and optionally starts the default HTTP endpoint.


Description

export const initPixstoreBackend = (
config: Partial<PixstoreBackendConfig> = {}
): void

Parameters

NameTypeDescription
configPartial<PixstoreBackendConfig>Optional runtime configuration for the backend.

Example

import { initPixstoreBackend } from 'pixstore/backend'

initPixstoreBackend({
defaultEndpointEnabled: false,
})

This will initialize the database and disable default image endpoint.

caution

If you disable the default endpoint just like this example you must implement your own image-serving endpoint using customEndpointHelper.

Otherwise, the frontend mechanism of this library can not fetch images automatically


How it works?

⚠️ This section shows internal implementation details.
It is intended for contributors or users who want to understand the inner workings of Pixstore. Typical users do not need to modify or interact with this code directly.
Also, this code was last verified with Pixstore v3.2.1 and may change in future versions. For the latest implementation, always check the official repository at github.com/sDenizOzturk/pixstore.
/**
* Initializes the Pixstore backend module with the given configuration.
* Starts the default endpoint if enabled.
*/
export const initPixstoreBackend = (
config: Partial<PixstoreBackendConfig> = {},
) => {
// Validates user config (e.g. cleanupBatch must be < cacheLimit)
// Then applies it to the internal Pixstore state
initPixstore(config)

// Prepares the database for storing image metadata
initializeDatabase()

// If enabled, starts the default image-serving HTTP endpoint
if (pixstoreConfig.defaultEndpointEnabled) {
startDefaultEndpoint()
}
}

📄 Source: src/backend/index.ts