GitXplorerGitXplorer
j

nano-config

public
1 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
1a5a913ce3c1c521a274360e3d347a81cbe53fc3

Fixed bug where load didn't return self

jjamesrom committed 11 years ago
Unverified
840e20b9a70b7c3d79641ac20eb55d8616d44610

fixed mistakes

jjamesrom committed 11 years ago
Unverified
65bb36cbd88c6e6942b183cd0a111d358e0468ca

fixed mistake

jjamesrom committed 11 years ago
Unverified
07b194335346cadc8be72a01fd598220bbd851e1

improved doc

jjamesrom committed 11 years ago
Unverified
547f29168d7e02abef4cda11cb873ede1be5fb22

Improved documentation and added repo to package.

jjamesrom committed 11 years ago
Unverified
ae88e6d3e1299397a23e49ab1ef442f2c99c2443

Fixed example

jjamesrom committed 11 years ago

README

The README file for this repository.

nano-config logo

A simple, dependency-free configuration helper with a nano API.

var config = require('nano-config')('./my-configuration.json');
config.greet = 'world';
config.save()

Loads my-configuration.json. If it doesn't exist it will be created when you call save.

{
  "greet": "world"
}

Okay, cool. You just saved some JSON. Who cares?

It's global

You only need to load a configuration file once. Here's some other part of your application.

var config = require('nano-config');
console.log(`hello ${config.greet}`);

Outputs

hello world

nano-config remembers the last config you loaded.

It's simple

nano-config doesn't depend on any modules, doesn't care about environment variables and doesn't have a verbose API.

Do you need to load a specific configuration file for a specific environment? Do it yourself.

var config = require('nano-config')(`./${process.env.NODE_ENV}.json`)

It's flexible

Custom serialization. Prefer CSON?

var CSON = require('cson');
var config = require('nano-config');
config.deserialize = str => CSON.parseSync(str);
config.serialize = obj => CSON.stringifySync(obj);
config('./my-config.cson');

Full API Documentation

config(file)

Loads a configuration file.

config.save(callback)

Saves the current configuration to file. Optional callback is called when save is finished.

config.serialize(obj)

The object serializer. It takes an object and returns a string.

config.deserialize(string)

The string deserializer. It takes a string and returns an object.