Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

standard-settings

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

standard-settings - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

44

index.js

@@ -9,4 +9,2 @@ // first settings loaded are stronger than last one

// TODO: load settings in data too
'use strict'

@@ -17,21 +15,33 @@

module.exports = () => {
nconf.env({
lowerCase: true,
separator: '_'
})
.argv()
nconf.env({
lowerCase: true,
separator: '_'
})
.argv()
if (nconf.get('settings') !== undefined) {
if (!fs.existsSync(nconf.get('settings'))) {
console.warn('File ' + nconf.get('settings') + ' does not exist and was not loaded. Other settings applied.')
} else {
nconf.file('cli', nconf.get('settings'))
}
if (nconf.get('settings') !== undefined) {
if (!fs.existsSync(nconf.get('settings'))) {
console.warn('File ' + nconf.get('settings') + ' does not exist and was not loaded. Other settings applied.')
} else {
nconf.file('cli', nconf.get('settings'))
}
}
nconf.file({ file: './settings/settings.json' })
.file('default', './settings/settings.default.json')
nconf.file({ file: './settings/settings.json' })
.file('default', './settings/settings.default.json')
return nconf.get()
function getMeta(media) {
let defaultMeta = nconf.get('media:meta')
if (defaultMeta === undefined) {
defaultMeta = {}
}
if (media) {
return Object.assign(defaultMeta, media.meta)
} else {
return defaultMeta
}
}
module.exports = {
getMeta
}
{
"name": "standard-settings",
"version": "1.0.1",
"version": "1.1.0",
"description": "Standardised settings loader",

@@ -5,0 +5,0 @@ "main": "index.js",

# standard-settings
Standardised settings loader
Note: First settings loaded are stronger than last one
## Installation
`npm install standard-settings --save`
or
`yarn add standard-settings`
## Usage
This module loads settings and store them using [nconf](https://github.com/indexzero/nconf).
It should be required at the very beginning of your project:
```
const standardSettings = require('standard-settings')
```
Then your settings are accessible from any file in your project using:
```
const settings = require('nconf').get()
```
If you need to directly access a specific field inside your settings, you can use:
```
const port = require('nconf').get('server:port')
```
## API
### getMeta(media)
- **parameters**: media (Object)
- **returns**: meta (Object)
- **description**: This function creates a new object resulting from the overload of the `media.meta` (from settings) with the `media.meta` (from media parameter) and returns its content.
## Priority order
### env
`$ SERVER_PORT=2500 node index.js` or `$ service_spacebro_inputMessage=new-media node index.js`
### Environment variables
Example:
`$ SERVER_PORT=2500 node index.js`
`$ service_spacebro_inputMessage=new-media node index.js`
### argv
`$ node index.js --server.port 2000`
### Command line parameters (argv)
Example:
`$ node index.js --server.port 2000` to specify a field
`$ node index.js --settings settings/settings.prod.json` to specify a settings file
### settings file with argv
`$ node index.js --settings settings/settings.prod.json`
### Files
These files are loaded if no `--settings` option is provided:
`settings/settings.json` first
`settings/settings.default.json` (if the first one does not exists)
### settings files
`settings/settings.json`
`settings/settings.default.json`
## Schema
The following schema is an example of settings used in Soixante circuits apps:
```
{
"server": {
"host" : "myip",
"port" : "3333"
},
"timeout": {
"lookbook": 5,
"popup": 4
},
"folder": {
"kcDownloader": "path-to/data",
"lookbook": "path-to/lookbook"
},
"flag": {
"stabalize": true,
"devMode": true
},
"customKey": {
"maxImageNumber": 64
},
"meta": {
"title": "",
"description": "",
"message": "...",
"source": ""
},
"service": {
"altruist": {
"host" : "192.168.1.6",
"port" : "6666"
},
"spacebro": {
"host" : "192.168.1.6",
"port" : "8888",
"channel": "lachaine",
"client" : "nomdelapp",
"inputMessage": "new-media",
"outputMessage": "new-media-processed"
}
}
}
```
See [soixantecircuits/standard](https://github.com/soixantecircuits/standard)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc