Configurations

appt.json

Because we are talking about "not to worry on filepaths", appt has to be able to glob require your project files to put them into appt's ecosystem. To do so, every appt's project must to have an appt.json file, which will contain the paths to be included and excluded into the project according to the environment(NODE_ENV). Also, that file may keep you project configurations. Let's see the example below:

package.json
{
"name": "demo",
"version": "1.0",
"scripts": {
"start": "export NODE_ENV=production && node ./dist/main.module.js",
"dev": "babel-node ./src/main.module.js"
},
"dependencies": {
"@appt/core": "1.0.30"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.24.1"
}
}
appt.json
{
"environments": {
"default": {
"include": ["src/**/*.js", "seeds/**/*.js"],
"exclude": ["src/**/*.ejs"],
"config": "./config/development"
},
"production": {
"include": ["dist/**/*.js"],
"exclude": ["dist/**/*.ejs"],
"config": "./config/production"
}
}
}
./config/development.js
./config/production.js
export default {
database: {
uri: 'mongodb://localhost:27017/appt-demo',
options: {
debug: true,
useNewUrlParser: true
}
}
}

What's gonna happen? When we execute npm start, before boot the program's entry file, our script into the package.json will export a production environment. That environment will be catched by appt, which will find for it into the appt.json file. Once found, the correspondent configurations will be merged with those into default environment, overriding the matched properties. Executing npm run dev, appt won't find any NODE_ENV exported. Then it will assume the default environment configurations.

@appt/core/config

Appt's configuration system is not required for any Appt's Project, but since our example is using it, let's assume the files above and see how it works running npm run dev:

import { database } from '@appt/core/config';
‚Äč
// will print: mongodb://localhost:27017/appt-demo
console.log(database.uri);

That's it! Now, your configurations are accessible in the whole project.