
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@iobroker/adapter-core
Advanced tools
Core module to be used in ioBroker adapters. Acts as the bridge to js-controller.
Core module to be used in ioBroker adapters. Acts as the bridge to js-controller.
This replaces the utils.js included in the ioBroker template adapter.
npm i @iobroker/adapter-coreconst utils = require(__dirname + '/lib/utils');
with
const utils = require('@iobroker/adapter-core');
// old style
const adapter = utils.adapter(/* options */);
// new style (classes). See https://github.com/ioBroker/ioBroker.template/ for a more detailed usage
class MyAdapter extends utils.Adapter {...}
Compared to the old utils.js, some utility methods were added.
getAbsoluteDefaultDataDirconst dataDir = utils.getAbsoluteDefaultDataDir();
This returns the absolute path of the data directory for the current host. On linux, this is usually /opt/iobroker/iobroker-data
getAbsoluteInstanceDataDir// old style
const instanceDataDir = utils.getAbsoluteInstanceDataDir(adapter);
// new style (classes)
const instanceDataDir = utils.getAbsoluteInstanceDataDir(this);
Returns the absolute path of the data directory for the current adapter instance.
On linux, this is usually /opt/iobroker/iobroker-data/<adapterName>.<instanceNr>
EXIT_CODESadapter.terminate('for some reason', utils.EXIT_CODES.ADAPTER_REQUESTED_TERMINATION);
Use standardized exit codes if your adapter needs to terminate.
commonToolsA collection of various utility methods and modules from JS-Controller. Prefer this over trying to find lib/tools.js and similar internal modules from the controller yourself!
Currently, the following methods are available:
commonTools.pattern2RegEx - Converts a pattern to match object IDs into a RegEx string that can be used in new RegExp(...)commonTools.getAdapterDir - Finds the adapter directory of a given adaptercommonTools.getInstalledInfo - Get a list of all installed adapters and controller version on this hostcommonTools.getLocalAddress - Get the localhost (IPv6 or IPv4) address according to the ioBroker configcommonTools.getListenAllAddress - Get the "listen all" (IPv6 or IPv4) address according to the ioBroker configcommonTools.isLocalAddress - Check if given IPv4 or IPv6 ip address corresponds to localhostcommonTools.isListenAllAddress - Check if given IPv4 or IPv6 ip address corresponds to "listen all" addresscommonTools.ensureDNSOrder - Ensure that DNS resolution is performed according to ioBroker configAnd the following modules are exposed:
commonTools.password - Previously exposed as lib/password.js in JS-Controller.commonTools.session - Previously exposed as lib/session.js in JS-Controller.commonTools.zipFiles - Previously exposed as lib/zipFiles.js in JS-Controller.commonTools.isDocker - Checks if we are running inside a docker containerNote that commonTools.letsEncrypt is not available anymore as the next controller won't support it (use @iobroker/webserver instead).
Developers can use internationalisation in backend.
For that call
const I18n = require('@iobroker/adapter-core').I18n;
// later in "ready" method
await I18n.init(__dirname, adapter);
// If you use class syntax, you can use `this` instead of `adapter`
await I18n.init(__dirname, this);
// You can provide the language directly
await I18n.init(__dirname, 'de');
and then in code
console.log(I18n.translate('text to translate %s', 'argument1'));
// Or you can use short form
console.log(I18n.t('text to translate %s', 'argument1'));
// or to get the ioBroker.Translated object
console.log(JSON.stringify(I18n.getTranslatedObject('text to translate %s and %s', 'argument1', 'argument2')));
You can place your i18n folder in root of adapter or in lib folder. If your i18n files are in lib directory, so call the init function like this:
const { join } = require('node:path');
const I18n = require('@iobroker/adapter-core').I18n;
await I18n.init(join(__dirname, 'lib'), adapter);
Expected structure of i18n directory
+ i18n
- de.json
- en.json
- es.json
- fr.json
- it.json
- nl.json
- pl.json
- pt.json
- ru.json
- uk.json
- zh-cn.json
And an example of i18n files could be found here
ioBroker has the ability to include files written by adapters in its backups. To enable that, you need to add the following to io-package.json:
{
// ...
"common": {
// ...
"dataFolder": "path/where/your/files/are"
}
}
This path is relative to the path returned by getAbsoluteDefaultDataDir(). The placeholder %INSTANCE% is automatically replaced by the instance number of each adapter, for example "dataFolder": "my-adapter.%INSTANCE%".
To keep the OAuth2 access token up to date, you can use the TokenRefresher class and do not forget to include axios in your adapter dependencies (in package.json).
import { TokenRefresher } from '@iobroker/adapter-core';
export class YourAdapter extends Adapter {
private tokenWorker?: TokenRefresher;
// It is important to call this method in the `onReady` method of your adapter and not in the constructor.
async onReady(): Promise<void> {
// Not in constructor, but in onReady
this.tokenWorker = new TokenRefresher(this, 'yourService');
// Your other initialization code...
// Then later in code, you can get the access token like this:
try {
const accessToken = await this.tokenWorker.getAccessToken();
this.log.info(`Spotify OAuth2 Token Refresher is ready: ${accessToken}`);
} catch (error) {
this.log.error(`Error initializing Spotify OAuth2 Token Refresher: ${error}`);
}
}
onStateChange(id: string, state: ioBroker.State | null | undefined): void {
// It detects `adapterName.X.oauth2Tokens` or similar
this.tokenWorker?.onStateChange(id, state);
// Your other state change code...
}
onUnload(callback: () => void): void {
this.tokenWorker?.destroy();
// Your other unload code...
callback();
}
}
Important to use OAuth2 infrastructure in your adapter contact the ioBroker team so we can implement a cloud code for https://oauth2.iobroker.in/YOUR_SERVICE_NAME. This will allow you to use the OAuth2 infrastructure in your adapter without having to implement it yourself.
Here is a description of how to implement OAuth2 in your adapter: https://github.com/ioBroker/ioBroker.admin/blob/master/packages/jsonConfig/OAUTH2.md
npm run build creates a clean rebuild of the module. This is done automatically before every build;npm run lint checks for linting errors;npm run watch creates an initial build and then incrementally compiles the changes while working.If you find errors in the definitions, e.g., function calls that should be allowed but aren't, please open an issue here or over at https://github.com/DefinitelyTyped/DefinitelyTyped and make sure to mention @AlCalzone.
@iobroker/types peer dependency@iobroker/webserver instead)esm and cjs exports@iobroker/types in built module@types/iobroker to @iobroker/typesnpm v7 or newer and/or Node.js 16 or newercommonTools exportcommonTools exportcommonTools exportv4.0.1 for support with JS-Controller 4.xv3.3.4.v3.3.0 to be up to date with JS-Controller 3.3.x.utils.EXIT_CODESadapter.objects and adapter.states. You must use the new methods adapter.getObjectView and adapter.getObjectList instead of their counterparts from objects.new.Copyright (c) 2018-2025 AlCalzone
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Core module to be used in ioBroker adapters. Acts as the bridge to js-controller.
The npm package @iobroker/adapter-core receives a total of 29,476 weekly downloads. As such, @iobroker/adapter-core popularity was classified as popular.
We found that @iobroker/adapter-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.