Lang/TypeScript
[Nest.js] 프로젝트 세팅 _ yaml
quantumee
2024. 10. 27. 20:42
1. yaml 파일 생성
>> 파일이름 : config.yaml
>> 파일 내용 예시 :
port: 4000
database:
host: localhost
user: username
pass: password
2. yaml 패키지 설치
pnpm add yaml
3. config.yaml 읽기 위한 파일
>> 위치 : src
>> 파일명 : config.ts
// src/config.ts
import * as fs from 'fs';
import * as yaml from 'yaml';
const configFile = fs.readFileSync(path.resolve(process.argv[2] || 'config.yaml'), 'utf8'); // 경로를 인자로 받을 수 있도록
const config = yaml.parse(configFile);
export default config;
ㄴ> yaml 경로를 하드코딩 해놓을 경우 배포후에 yaml 파일 위치가 달라지면 설정이 안되기 때문에
저렇게 설정해서 start 할때 config파일을 위치를 지정할 수있도록 했다.