---
title: registry
slug: develop/registry
docTags: 
createdAt: 2025-03-26T14:48:28.979Z
---

The *registry* object allows you to read from and write to the player registry (i.e. the persistent memory). The registry consists of named registry sections, and each registry section contains entries (key/value pairs).

**registry IDL**

```javascript
interface Registry {
    Promise<String> read(String sectionName, String key);
    Promise<RegistrySection> read(String sectionName);
    Promise<RegistryObject> read();

    Promise<void> write(String sectionName, String key, String value);
    Promise<void> write(String sectionName, RegistrySection section);
    Promise<void> write(RegistryObject);

    Promise<void> flush();
};
```

## Object Creation

To create a *registry* object, first load the `brightsign/registry` module using the `require()` method. Then create an instance of the *registry* class.

```javascript
var registryClass = require("@brightsign/registry");
var registry = new registryClass();
```

## Registry

Use this interface for registry read/write operations. 

:::hint{type="info"}
All section and key names are canonicalized to lowercase. 
:::

**read()**

```javascript
Promise<String> read(String sectionName, String key)
```

Returns the string registry value associated with the specified key. You must also specify the registry section where the key is stored.

```javascript
Promise<RegistrySection> read(String sectionName)
```

Returns the specified registry section in the following format: `RegistrySection.{entry_key}.`

```javascript
Promise<RegistryObject> read()
```

Returns all registry sections in the following format: `RegistryObject.{section_name}.{entry_key}.`

**write()**

```javascript
Promise<void> write(String sectionName, String key, String value)
```

Writes a single registry entry to the specified registry section.

```javascript
Promise<void> write(String sectionName, RegistrySection section)
```

Writes the specified registry section to the registry. If the registry section does not exist, it will be created; otherwise, the entries will be added or updated in the existing registry section (preexisting registry entries that are not specified in the write operation will be unaffected).

```javascript
Promise<void> write(RegistryObject)
```

Writes the specified registry sections/entries to the registry. Registry sections and entries that do not exist will be created, and existing entries will be updated (preexisting registry sections/entries that are not specified in the write operation will be unaffected).

:::hint{type="info"}
The single-entry `write()` method will not perform well when used to write multiple entries successively. For optimal performance, use the single-section `write()` method to write multiple entries to a single section and the full-registry method to write to multiple sections.
:::

:::hint{type="info"}
Sixty seconds at most after a write to the registry, or before an orderly reboot, the newly written data will be automatically be written out to persistent storage. If for some reason, a set of registry changes must be written immediately, then the `flush()` method should be called after the last one.
:::

:::hint{type="danger"}
While it is possible to read the entire registry, modfiy the return value, and write it back into the registry, this is not a recommended practice: It may cause race conditions among different parts of the system that are attempting to write to the registry at the same time.
:::

flush()

```javascript
Promise<void> flush()
```

Flushes the contents of the registry immediately to persistent storage.

:::hint{type="success"}
To delete a registry entry or section, assign it a `null` value.
:::

## Example

```javascript
var registryClass = require("@brightsign/registry");
var registry = new registryClass();
 
//Reads the entire registry to the log.
registry.read().then(function(registry) {
    console.log(JSON.stringify(registry));
});
 
//Reads the contents of the "networking" registry to the log.
registry.read("networking").then(
	function(registry){console.log(JSON.stringify(registry));});
 
//Writes multiple entries to multiple sections.
registry.write({networking:{ssh:"22", http_server:"8080"}, autorun:{devicesetupcomplete:"1"}} ).then(
	function(){console.log("Write Successful");});
 
//Updates a single section.
registry.write("networking", {ssh:"22", http_server:"8080"}).then(
	function(){console.log("Write Successful");});
 
//Deletes a registry section and entry, and creates a new section.
registry.write({networking:{ssh:"22", http_server:null}, autorun:null, section1:{test:"val"}} ).then(
	function(){console.log("Write Successful");});
```

