# Plugins

{% hint style="danger" %}
Make sure you trust the plugin as they have access to your database. Read [below](#access) on a way around this.&#x20;
{% endhint %}

### 1. Create a file with the plugins you wish to use

{% code title="my\_plugins.js" lineNumbers="true" %}

```javascript
module.exports = {
    package_example: require("dubnium-test-pkg"),
    function_example: () => { console.log("Hello, world") },
}
```

{% endcode %}

### 2. Load the file

{% hint style="warning" %}
You must run the `loadFromFile()` method before the plugin can be used.
{% endhint %}

{% code title="update\_plugins.js" lineNumbers="true" %}

```javascript
const { PluginManager } = require("dubnium")
PluginManager.loadFromFile('./path/to/my_plugins.js')
```

{% endcode %}

Be sure to run this! You can check if the plugin is registered by checking `PluginManager.activePlugins`. If you updated Dubnium, the plugins may have been reset.

### 3. Use the Plugin

Allow access to **all** data

{% code title="index.js" lineNumbers="true" %}

```javascript
const { Dubnium } = require("dubnium")
const db = new Dubnium('./test_db','json')
db.usePlugin("name")
```

{% endcode %}

### Customize Plugin's access <a href="#access" id="access"></a>

If you do not want to give access to your data through Dubnium, you can also access the `plugins` property.

{% code title="index.js" lineNumbers="true" %}

```javascript
const { Dubnium } = require("dubnium")
const db = new Dubnium('./test_db','json')
db.plugins.name(database, record)
```

{% endcode %}

{% hint style="info" %}
Plugins may ask for database & record (calling the `usePlugin` method automatically passes them both, if possible). You can set either to `null` if you do not wish to give access.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://db.coolstone.dev/2/plugins.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
