Settings Tutorial

This tutorial will show you how to manage settings, and how to create your own settings adapter.

The Settings adapter handles settings requests.



const settings = core.make('osjs/settings');

// Saves all settings;

// Loads all settings

// Gets a settings object from a namespace

// Sets a settings object to a namespace
settings.set('some/namespace', 'key', 'value')


An application is given the namespace osjs/application/{name} (where the name is taken from your application metadata):

import {name as applicationName} from './metadata.json';

OSjs.make('osjs/packages').register(applicationName, (core, args, options, metadata) => {
  // Default settings
  options.settings = {
    foo: 'bar'

  const proc = core.make('name', {options, args, metadata});

  // Get a setting
  console.log(; // => "bar"

  // Set a setting = 'baz';

  // Save settings
    .then(() => console.log('done'));

  return proc;

Custom Settings Adapter

To set up your adapter, see the settings guide.

To generate a new adapter using the example via CLI run npm run make:settings.

For general information about development see development article.


const myAdapter = (core, options) => ({
  async save(values) {
    // Create your own request here with 'values' settings
    return true;

  async load() {
    // Create your own request here and return settings
    return {};

export default myAdapter;


module.exports = (core, options) => ({
  async save(req, res) {
    // req.body has all settings from client
    return true;

  async load(req, res) {
    // return all settings for user here
    return {};

Using classes

You can also use class pattern for your adapter:

class MySettingsAdapter {
  constructor(core, options) {
    this.core = core;
    this.options = options;

  async save(values) {
    return true;

  async load() {
    return {};

// or for server: module.exports = function()
export default function(core, options) {
  return new MySettingsAdapter(core, options);
OS.js Web Desktop - © Anders Evenrud <>

results matching ""

    No results matching ""