nestJS: 프레임워크
express : 라이브러리 규모
.eslintrc.js : 코딩문법규칙('=='금지 등) 정하기
.prettierrc: 코딩정리규칙 정하기
yarn.lock :해당 라이브(ex-eslint)를 만든 사람이 사용한 라이브러리들을 저장
dependencies :
서버 실행시 필요한 라이브러리
배포할 때 필요O
devdependencies:
vscode실행시 필요한 라이브러리
배포할 때 필요X
main.ts :
1.시작(서버를 실행(turn on)시키는 부분
2.모듈을 등록하는 부분
app.controller.ts: 실제 API가 존재하는 곳
app.module.ts: 의존성 주입이 발생하는 곳
app.service.ts: 서비스(=비즈니스 로직)
app.module.ts에서는 의존성 주입이 발생한다!!
const boardService = new BoardService();
const boardController = new BoardController(boardService);
의존성 주입 → 강한 결합을 약한 결합으로 만들기 위함
해당 클래스(BoardController)가 아닌 외부의 환경 설정 config클래스(API목록)에서
객체를 생성한 후 BoardController의 생성자를 통해서 객체(BoardService)를 주입받는 것을 말한다.
NestJS에서는 의존성 주입이 이미 구현되어 있다.
//타입스크립트 기초
//타입추론
let aaa = "안녕하세요";
aaa = 3; //bad
//타입명시
let bbb: string = "반갑습니다.";
bbb = 10;
//타입명시가 필요한 상황
let ccc: string | number = "반갑습니다.";
ccc = 10;
//숫자타입
let ddd: number = 123;
ddd = "철수";
//불립타입
let eee: boolean = true;
eee = false;
eee = "false"; //조건문에서 true인식된다. ㅠ.ㅠ
/**
0 : 거짓
0이 아닌 나머지 : 참 → -1은 참이다.
"": 거짓
'': 거짓
"철수" : 참
'철수' : 참
"false" : 참
'false' : 참
" " : 참
' ' : 참
→ 문자열에 "뭐 하나만 들어가 있으면" 참이다.
*/
let fff: number[] = [1, 2, 3, 4, "안녕"];
let ggg: string[] = ["철수", "영희", "훈이"];
let hhh: (string | number)[] = [1, 2, 3, 4, "안녕"];
let isActiveList: (boolean | string)[] = [true, false, "false", "true", false];
//객체타입
interface IProfile {
name: string;
age: number | string;
school: string;
hobby?: string;
//hobby는 있어도 되고 없어도 된다.
}
let profile: IProfile = {
name: "철수",
age: 8,
school: "다람쥐초등학교",
};
profile.age = "8살";
profile.hobby = "수영";
//함수타입
//함수의 매개변수의 경우 type추론이 안된다.
//따라서 명시를 해주어야 한다.
//return에도 타입을 명시할 수 있다.
const add1 = (money1: number, money2: number, unit: string): string => {
return money1 + money2 + unit;
};
const result1 = add1(1000, 2000, "원");
// add1(1000, "2000", "원"); //오류발생
키워드에 따른 접근제한
// 1. public
class Aaa {
constructor(public mypower) {
this.mypower = mypower; // public, private, readonly 중 1개만 포함되면 자동으로 셋팅됨
}
ggg() {
console.log(this.mypower);
}
}
const aaa = new Aaa(50);
aaa.mypower = 5; // 밖에서도 가능
// 2. private
class Bbb {
constructor(private mypower) {
// this.mypower = mypower; // public, private, readonly 중 1개만 포함되면 자동으로 셋팅됨
}
ggg() {
console.log(this.mypower);
}
}
const bbb = new Bbb(50);
bbb.mypower = 5; // 밖에서 불가능
// 3. readonly
class Ccc {
constructor(readonly mypower) {
// this.mypower = mypower; // public, private, readonly 중 1개만 포함되면 자동으로 셋팅됨
}
ggg() {
console.log(this.mypower);
this.mypower = 10; // 안에서도 불가능
}
}
'고농축 백엔드' 카테고리의 다른 글
고농축 벡엔드 11 - AccessToken과 Header의 Authorization// fetchUser() (0) | 2023.02.13 |
---|---|
고농축 백엔드 docker-bind★★ (0) | 2023.01.31 |
고농축 백엔드 9 - 객체, 약한결합, 강한결합, 의존성, 의존성주입 (0) | 2023.01.25 |
고농축 백엔드 8 - 도커 컴포즈, volume 마운트, moongoose (0) | 2023.01.25 |
고농축 백엔드 7 - docker 명령어 정리 (0) | 2023.01.22 |