# easy-nodejs-app-settings

> With this module you can easily save settings of your Nodejs App or Electron App.

Latest version **0.0.35** (published 2022-09-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install easy-nodejs-app-settings
pnpm add easy-nodejs-app-settings
yarn add easy-nodejs-app-settings
bun add easy-nodejs-app-settings
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.35 |
| Published | 2022-09-05 |
| First published | 2021-04-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Steffen Reimann |
| Maintainers | herbbert |

## Links

- npm: https://www.npmjs.com/package/easy-nodejs-app-settings
- Repository: https://github.com/steffenreimann/easy-nodejs-app-settings
- Homepage: https://github.com/steffenreimann/easy-nodejs-app-settings#readme
- Issues: https://github.com/steffenreimann/easy-nodejs-app-settings/issues
- npm.io page: https://npm.io/package/easy-nodejs-app-settings

## Recent versions

- 0.0.35 (latest) — 2022-09-05
- 0.0.34 — 2022-08-03
- 0.0.33 — 2022-08-03
- 0.0.32 — 2022-04-26
- 0.0.31 — 2021-09-02
- 0.0.3 — 2021-07-29
- 0.0.21 — 2021-07-14
- 0.0.2 — 2021-05-25
- 0.0.1 — 2021-04-12
- 1.0.0 — 2021-04-12

## README

# easy-nodejs-app-settings


With this module you can easily save settings of your Nodejs App or Electron App.


## Use Module

### Install
```javascript
npm install easy-nodejs-app-settings --save
```
### Run Test
This test will be ckeck if the module is working. And has the right permissions. 
```javascript
cd node_modules/easy-nodejs-app-settings

npm run test
```
### require
```javascript
const fm = require('easy-nodejs-app-settings')
```


### Init with async function and await
```javascript

async function init(){
	var DataStore = new fm.File({ 
		appname: 'YOUR-APP-NAME', // required
		file: 'DataStore.json', // required
		data: {}, // Optional, Set Data on Init only if the file is newly created or overwriteOnInit is true
		overwriteOnInit: true, // Optional, Set true if you want to overwrite the file on init. Attention the whole file will be overwritten! 
		interval: 5000, // Optional, if not set the interval no File watcher will be created 
		doLogging: false // Optional
	})

	await DataStore.init()
	console.log('DataStore File Init')
	console.log(DataStore.data)
}
```		

### Events
```javascript
DataStore.event.on('change', (data) => {
	console.log('Event change: ');
});

DataStore.event.on('remove', (data) => {
	console.log('Event remove: ');
});

```


### Set Entry File
```javascript
try {
	await DataStore.set({user: {name: 'John Doe', age: 30, email:''}});
} catch (error) {
	console.log('Error: ', error);
}
```

### get Entry File without reloading from Drive
```javascript
console.log(DataStore.data);
```

### get Entry File with reloading from Drive
```javascript
await DataStore.get();
```

### remove File from Drive
```javascript
await DataStore.remove();
```


## JSON Files only

### Set Key Value
```javascript
await DataStore.setKey({ 'user.name': 'herbbert', 'user.age': '28' });
```
### Get Key Value
```javascript
await DataStore.getKey('user.name');
```

### Push to Array or Assign to Object
#### if you want to push to an Array or Assign data to an Object, the array or object must be defined in the file
```javascript
// Define an Array
await DataStore.setKey({ testArr: [ 1, 2 ] });
// Define an Object
await DataStore.setKey({ testObj: { A: 1, B: 2 } });
```

### push Value to Array or Object
```javascript
//Push to Array
await DataStore.push({ testArr: 3 });
//Assign to Object
await DataStore.push({ testObj: { C: 3, D: 4 } });
```

---
_Source: https://npm.io/package/easy-nodejs-app-settings · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
