2.1.2 • Published 4 years ago
read-appsettings v2.1.2
read-appsettings-json | Simple and easy read appsettings.json file
read-appsettings-json is an easy way to read a local app settings file in a json format.
- Follow me @ http://codechavez.com
read-appsettings-json
Getting Started
install read-appsettings-json through npm package using the following command:
`npm install read-appsettings-json --save`
You need to create a appsettings.json file in the root of your project. Let's create the following appsettings.json
{
"apiendpoint": "http://localhost:3035",
"second":2,
"booleanflag":true
}
Now, this like is in a default root as ../../../appsettings.json which can be found at \node_modules\read-appsettings-json\dist\index.js
once you install the package. To access to you property just type its name as shown in the examples below.
Important to remember that you can create different settings as need it.
- use it as following
// Service Class
import { AppConfiguration } from "read-appsettings-json";
console.log(AppConfiguration.Setting().apiendpoint);
ANOTHER Example
{
"day": 1,
"year":2017,
"month":12
}
TYPESCRIPT WOULD BE
// Service Class
import { AppConfiguration } from "read-appsettings-json";
console.log(AppConfiguration.Setting().month)
Don't forget to add this code on your tsconfig.json, otherwise appsettings.json will be included into the bundle, defeating the purpose of this library, NO GOOD.
{
// Your code
"exclude": [
"**/appsettings.json",
"**/appsettings.Development.json"
]
}