# 高级配置
# 环境变量
支持通过环境变量配置应用:
export APP_DEBUG=true
export APP_PORT=3000
export APP_SECRET=your-secret-key
1
2
3
2
3
# 配置文件
创建 config.json:
{
"server": {
"host": "0.0.0.0",
"port": 3000
},
"database": {
"url": "mongodb://localhost:27017",
"name": "myapp"
},
"cache": {
"enabled": true,
"ttl": 3600
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 多环境配置
config/
├── default.json
├── development.json
├── production.json
└── test.json
1
2
3
4
5
2
3
4
5
# 自定义日志
import { createLogger } from 'my-awesome-lib'
const logger = createLogger({
level: 'debug',
format: 'json',
output: './logs/app.log'
})
1
2
3
4
5
6
7
2
3
4
5
6
7
# 性能优化
- 启用缓存
- 使用连接池
- 开启 gzip 压缩
- 配置 CDN