https://github.com/kettek/node-desktop-app-settings
Module providing multi-platform application settings with automatic saving and creation.
https://github.com/kettek/node-desktop-app-settings
app configuration electron nodejs nwjs settings
Last synced: about 2 months ago
JSON representation
Module providing multi-platform application settings with automatic saving and creation.
- Host: GitHub
- URL: https://github.com/kettek/node-desktop-app-settings
- Owner: kettek
- License: lgpl-3.0
- Created: 2019-08-15T10:55:32.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-03-12T08:30:13.000Z (over 6 years ago)
- Last Synced: 2025-10-24T15:56:04.042Z (8 months ago)
- Topics: app, configuration, electron, nodejs, nwjs, settings
- Language: JavaScript
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# node-desktop-app-settings
This npm module provides generic desktop application settings for Linux, Mac OS, and Windows. It runs synchronously for reading and writing. It automatically loads a settings JSON file on invocation and saves the file when node exits.
## Usage
Usage is fairly simple:
let ndas = require('node-desktop-app-settings')
let myConfig = ndas('MyProgramName')
myConfig.settings.myOption = 123;
After this, whether from Ctrl-C, sigs, or regular closing of the program, the data file will be saved to `USERDATA/settings.json`.
### API
#### NDAS(, [options])
`require('node-desktop-app-settings')` returns a function that is used to create a desired settings.
##### options
An options object can optionally be passed to the NDAS constructor. The possible options are:
* `saveOn`: `["exit", "SIGINT", "unhandledException"]`
* Setting this to an empty array will prevent any sort of saving on program exit.
* `appData`: ``
* Manually override the default appData location.
* `userData`: ``
* Manually override the default userData location.
* `settingsPath`: ``
* Manually override the default settings path.
##### Example
```
let ndas = require('node-desktop-app-settings')
let myConfig = ndas('MyProgram')
```
---
```
let myConfig = require('node-desktop-app-settings')('MyProgram')
````
#### config.settings
This property is the object that is saved on a call to `save()` or program exit. If `options.saveOn` is set to an empty array, this will not automatically by saved.
#### config.appData
This property returns:
* MacOS: /Users/user/Library/Preferences
* Linux: /home/user/.local/share
* Windows 8+: C:\Users\user\AppData\Roaming
* Windows XP: C:\Documents and Settings\user\Application Data
**NOTE**: This uses the APPDATA or HOME environment variables along with some OS detection. See source for details.
#### config.userData
This property returns the appData path with the first argument passed to `ndas()`.
##### Example
```
let myConfig = require('node-desktop-app-settings')('MyProgram')
console.log(myConfig.userData) // returns appData + "/MyProgram"
```
#### config.settingsPath
This property returns the corresponding `settings.json` file path.
##### Example
```
let myConfig = require('node-desktop-app-settings')('MyProgram')
console.log(myConfig.settingsPath) // returns userData + "/settings.json"
```
#### config.save()
Saves the settings synchronously.
##### Example
```
myConfig.save()
```
#### config.clear()
Clears the current settings to an empty state.
##### Example
```
myConfig.close()
```