<commit_before>## Configuration

ThinkJS provides a flexible configuration mechanism, it can use different configuration in different modules and project environments, and these configurations will take effective after service started.

`Note: Do not set the private value of an http request in the configuration, because other http setting may overriding these values.`

### The Project Module

The projects that created default by ThinkJS are divided according to the module, you can define different configuration under each module. General configuration can be defined under `common` modules, other modules will inherit the `common` configuration.

### Project Environment

ThinkJS default support three kinds of project environments, it can be configured according to the different environment, in order to meet the needs of the different situations of configuration.

* `development` development
* `testing` testing
* `production` production

It can also be extended to other environment in project, which kind of environment to use at present can be set in the [entrance file](./app_structure.html#toc-f0b), and set the `env` value.

### Defining Configuration Files

##### config/config.js

For some basic configuration, such as:

```js
export default {
  port: 8360, 
  host: '',
  encoding: 'utf-8',
  ...
}
```

##### config/[name].js

For a specific independent function configuration, such as `db.js` is the database configuration, `redis` is redis configuration.

```js
// db.js
export default {
  type: 'mysql',
  host: '127.0.0.1',
  port: '',
  name: '',
  user: '',
  ...
};
```

##### config/env/[mode].js

Differentiation configuration in different project environment, such as `env/development.js`,`env/testing.js`,`env/production.js`.

```js
// config/env/development.js
export default {
  port: 7777,
  db: { //开发模式下数据库配置
    type: 'mysql',
    host: '127.0.0.1',
    port: '',
    ...
  }
}
```

`Note`: The differences of different environments generally is not too much, so we defined them in a single file. At this time, if you want to modify an independent function configuration, you need to add a key corresponding to the independent function. Such as you need to add the the name of the `db` corresponding to the database when modifing the database configuration, as shown above.

##### config/locale/[lang].js

International language pack configuration, such as `locale/en.js`,`locale/zh-cn.js`.

--------

Configuration format uses the form of `key: value`, and the `key` is case-insensitive.

### Loading Configuration Files

ThinkJS supports multiple levels of the configuration file, it reads in the following order:

`default configuration of the framework - > framework configuration under project mode - > project common configuration - > common configuration under project mode - > module configuration`

### Reading Configuration

#### Using config

In Controller, Logic, Middleware, you can using `this.config`. Such as:

```js
let db = this.config('db'); // reading all of the configurations about db
let host = this.config('db.host'); // reading the host configuration about the host of db
```

#### Using http.config

`http` objects also have the `config` method used for obtain the relevant configuration, such as:

```js
let db = http.config('db');
```

#### Reading Configuration From Other Places

In other places, we can read the relevant configuration through `think.config`:

```js
let db = think.config('db'); // reading the configuration about db under the common configuration
let db1 = think.config('db', undefined, 'home'); // get the da configuration under the home module
```

`Note`: Before parsing route, we can not get the general module configuration through the `config` method or `http.config` method, so the configuration which is used before route parsing must be defined in the general module.

### The Default Configuration

#### env

Project configuration mode, the `config/env/development.js`.

```js
export default {
  auto_reload: true,
  log_request: true,
  gc: {
    on: false
  },
  error: {
    detail: true
  }
}
```

Th `config/env/testing.js` and `config/env/produciton.js` have no default configuration.
<commit_msg>Th replace The<commit_after>## Configuration

ThinkJS provides a flexible configuration mechanism, it can use different configuration in different modules and project environments, and these configurations will take effective after service started.

`Note: Do not set the private value of an http request in the configuration, because other http setting may overriding these values.`

### The Project Module

The projects that created default by ThinkJS are divided according to the module, you can define different configuration under each module. General configuration can be defined under `common` modules, other modules will inherit the `common` configuration.

### Project Environment

ThinkJS default support three kinds of project environments, it can be configured according to the different environment, in order to meet the needs of the different situations of configuration.

* `development` development
* `testing` testing
* `production` production

It can also be extended to other environment in project, which kind of environment to use at present can be set in the [entrance file](./app_structure.html#toc-f0b), and set the `env` value.

### Defining Configuration Files

##### config/config.js

For some basic configuration, such as:

```js
export default {
  port: 8360, 
  host: '',
  encoding: 'utf-8',
  ...
}
```

##### config/[name].js

For a specific independent function configuration, such as `db.js` is the database configuration, `redis` is redis configuration.

```js
// db.js
export default {
  type: 'mysql',
  host: '127.0.0.1',
  port: '',
  name: '',
  user: '',
  ...
};
```

##### config/env/[mode].js

Differentiation configuration in different project environment, such as `env/development.js`,`env/testing.js`,`env/production.js`.

```js
// config/env/development.js
export default {
  port: 7777,
  db: { //开发模式下数据库配置
    type: 'mysql',
    host: '127.0.0.1',
    port: '',
    ...
  }
}
```

`Note`: The differences of different environments generally is not too much, so we defined them in a single file. At this time, if you want to modify an independent function configuration, you need to add a key corresponding to the independent function. Such as you need to add the the name of the `db` corresponding to the database when modifing the database configuration, as shown above.

##### config/locale/[lang].js

International language pack configuration, such as `locale/en.js`,`locale/zh-cn.js`.

--------

Configuration format uses the form of `key: value`, and the `key` is case-insensitive.

### Loading Configuration Files

ThinkJS supports multiple levels of the configuration file, it reads in the following order:

`default configuration of the framework - > framework configuration under project mode - > project common configuration - > common configuration under project mode - > module configuration`

### Reading Configuration

#### Using config

In Controller, Logic, Middleware, you can using `this.config`. Such as:

```js
let db = this.config('db'); // reading all of the configurations about db
let host = this.config('db.host'); // reading the host configuration about the host of db
```

#### Using http.config

`http` objects also have the `config` method used for obtain the relevant configuration, such as:

```js
let db = http.config('db');
```

#### Reading Configuration From Other Places

In other places, we can read the relevant configuration through `think.config`:

```js
let db = think.config('db'); // reading the configuration about db under the common configuration
let db1 = think.config('db', undefined, 'home'); // get the da configuration under the home module
```

`Note`: Before parsing route, we can not get the general module configuration through the `config` method or `http.config` method, so the configuration which is used before route parsing must be defined in the general module.

### The Default Configuration

#### env

Project configuration mode, the `config/env/development.js`.

```js
export default {
  auto_reload: true,
  log_request: true,
  gc: {
    on: false
  },
  error: {
    detail: true
  }
}
```

The `config/env/testing.js` and `config/env/produciton.js` have no default configuration.

{'fraction_non_alphanumeric': 0.1021671826625387, 'fraction_numerical': 0.005477494641581329, 'mean_word_length': 4.272441933458882, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6928296', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2126, 'n_words': 1032}