인프런 탄탄한 백엔드 NestJS, 기초부터 심화까지 강의의 express 핵심 원리 챕터를 들으며
기억할 부분을 기록한 글입니다.
https://www.staging-typescript.org/tsconfig
tsconfig.json에 설정된 대로 컴파일 됨
컴파일 결과물은 outDir 경로에 js파일로 생성됨
tsc : 컴파일러
tsc-watch : 계속 파일을 지켜봄 (파일 변경)
"scripts": {
"build": "tsc",
"start:dev": "tsc-watch --onSuccess \"node dist/app.js\"",
"prestart": "npm run build",
"start": "node dist/app.js"
}
npm run start:dev
입력하면 tsc-watch --onSuccess \"node dist/app.js\"가 실행됨npm run start
입력하면 prestart가 먼저 실행되고, build에서 tsc로 컴파일함app.use((req, res, next) => {
console.log(req.rawHeaders[1]);
next();
});
app.get('/test', (req, res, next) => {
console.log(req.rawHeaders[1]);
next();
});
GET /test
메서드를 처리하는 라우터에만 적용하고 싶으면 app.use가 아니라 위와 같이 쓰면 됨app.use(express.json());
// cat은 기존 cat 객체로 이미 선언되어있음
const body = req.body;
cat = {...cat, ...body};
소통해요