1. app.ts
1) config
https://www.npmjs.com/package/config?activeTab=readme
config
Configuration control for production node deployments. Latest version: 3.3.9, last published: a year ago. Start using config in your project by running `npm i config`. There are 4787 other projects in the npm registry using config.
www.npmjs.com
- Node-config organizes hierarchical configurations for your app deployments.
- stored in configuration files : ./config
1) define a set of default parameters
2) extend them for different deployment environments (development, qa, staging, production, etc.)
process.env["NODE_CONFIG_DIR"] = __dirname + "/configDir/";
const config = require("config");
2) process.env : 환경변수
https://www.daleseo.com/js-node-process-env/
Node.js에서 환경 변수 다루기 (process.env)
Engineering Blog by Dale Seo
www.daleseo.com
(1) 환경 변수가 필요한 이유
- 여러 환경에 동일한 애플리케이션을 배포하려면 환경 변수 필요
(2) 환경변수란?
- 코드베이스가 하나
- 개발, 테스트, 운영 등 여러 환경에 애플리케이션 배포
- 여러 환경에 배포할 때 다르게 설정해야 하는 값들을 운영체제 수준에서 환경 변수를 통해 관리할 수 있다
오버라이딩 방법
1) $node_config_dir 환경 변수를 세팅하면 오버라이딩을 할 수 있다
process.env["NODE_CONFIG_DIR"] = __dirname + "/configDir/";
const config = require("config");
2) 환경변수 접근
node.js에서는 보통 process.env를 통해 환경 변수에 접근
process는 node.js에 기본적으로 내장된 전역 객체여서 별도로 불러올 필요 없이 프로그램의 어디에서든지 사용할 수 있음
일부 환경 변수들은 우리가 직접 설정해주지 않더라도 운영 체제 수준에서 이미 설정되어 있다
터미널을 열고 node.js 인터프리터를 실행하면 어떤 환경 변수들이 이미 설정되어 있는지 간단하게 확인 가능
can be overridden and extended by environment variables, cli parameters or external sources;
Configurations are stored in configuration files within your application, and can be overridden and extended by environment variables, command line parameters, or external sources.
This gives your application a consistent configuration interface shared among a growing list of npm modules also using node-config.
- webpack
- bin
- campuspick_com.key/pem
- config
- data
- dist
- modules
- node_modules
- package.json
- package-lock.json
- routers
scripts
server.ts
static
submodules
tsconfig.json
tsconfig.ui.json
views
webpack
- common
- dev
- prod