# 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 %}
