https://github.com/reactive-stack-js/rsjs-config
rsjs-config
https://github.com/reactive-stack-js/rsjs-config
config typescript
Last synced: 10 months ago
JSON representation
rsjs-config
- Host: GitHub
- URL: https://github.com/reactive-stack-js/rsjs-config
- Owner: reactive-stack-js
- License: unlicense
- Created: 2020-12-18T11:31:31.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2020-12-18T19:18:16.000Z (almost 5 years ago)
- Last Synced: 2025-02-11T17:15:59.216Z (10 months ago)
- Topics: config, typescript
- Language: JavaScript
- Homepage: https://reactive-stack-js.github.io/rsjs-config/
- Size: 176 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rsjs-config
[](https://travis-ci.org/reactive-stack-js/rsjs-config)
[](https://www.codacy.com/gh/reactive-stack-js/rsjs-config/dashboard)
[](https://coveralls.io/github/reactive-stack-js/rsjs-config?branch=master)
[](https://www.npmjs.com/package/rsjs-config)
[](https://www.npmjs.com/package/rsjs-config) [](https://greenkeeper.io/)
## Requirements
The config files have to be in a _dedicated_ folder, but the location of this folder and its name are up to you.
This dedicated folder _cannot have any subfolders_ except one _optional_ folder which has to be called __env__. This _
optional_ __env__ folder can only contain environment specific overrides, like development, stage, production or any
other environment value you may set NODE_ENV to be.
The config files can be either ```.ts```, ```.js``` or ```.json``` files. And they can also be mixed, if you want to
play like that.
The ```.json``` files have to contain a pure json object with configurations.
The ```.ts``` and ```.js``` should export the json config:
```typescript
module.exports = {
...
}
```
The names of config files are used as the config root keys.
### Optional .env file
Optionally, you can also use a ```.env``` file with secret overrides, which you can also name as you wish. This file
should not be commited to your repository and is normally used for passwords. Standard files are ```.env```
, ```.env,local```, ```.local``` and so on.
This file requires a __namespace__ _word_ that will be used as the prefix for _every_ config value in it.
For example, if we want to define the ```foo.pwd``` value, and we decided to use ```blah``` as our namespace, then ```.env``` file would have:
```
blah.foo.pwd = "verysecretpwd"
```
## Usage
Let's say our project is structured as follows:
```bash
├─── main.js
├─── config
│ ├─── env
│ │ ├─── stage.js
│ │ └─── production.js
│ ├─── one.js
│ └─── two.js
├─── .env
```
Then, in ```one.js``` we can have keys ```foo``` and ```bar```, with some content. In ```two.js``` we can have
keys ```goo``` and ```car```, with some content.
In ```stage.js``` we have ```foo.dburl``` for the stage environment database. In ```production.js``` we
have ```foo.dburl``` for the production environment database.
Finally, in ```.env``` we have ```blah.foo.pwd``` for the database password. This file has to exist in each environment and
contain different environment values.
Then, this is how we initiate the RsConfig instance, in ```main.js```:
```javascript
// main.js
const path = require("path");
const RsConfig = require("rsjs-config");
RsConfig.init(path.join(__dirname, 'config'), {
file: path.join(__dirname, '.env'),
word: 'blah'
});
const dburl = RsConfig.get('one.foo.dburl');
...
```
## Documentation
[TypeDoc documentation](https://reactive-stack-js.github.io/rsjs-config/docs/)