studying (8) 썸네일형 리스트형 NodeJS(1) File System (fs) module In order to read and write files, you need to use fs modules. Let's look at the example right away to see how fs module works. Ex. So in line 1, you first enable readFileSync, writeFileSync by requiring the fs module. Then, I made two text files to use the readFileSync function -> and simply put the path of the file I want to read in the first parameter and the character encoding type in the sec.. NodeJS (0) What is NodeJS? NodeJS is simply a Javascript runtime environment where it allows people to use Javascript out of a web browser. Now, it's a popular tool for building server-side applications, web servers, etc. Typescript (7) Generics 우선 바로 간단한 예시를 보자 예) export const hi = (arg: string) => { return console.log("Hi", name); }; const v1 = hi("Daniel"); const v2 = hi(1234); // 여기 argument가 string이여야하는데 number을 넣어줬기 때문에 에러가난다 이렇게 hi라는 function을 만들고 arg:string으로 만들어줌으로써 v2의 arg는 number이기 때문에 에러가 난다 이렇게 arg의 type이 항상 똑같이 않을 경우 generics를 쓰는데 다음 generics를 쓴 예시를 보자 export const hi = (arg: T) => { return console.log("Hi", name); }; con.. MySQL (0) Upsert Upsert를 사용하면 간결하게 database 안에 있는 data들을 간단하게 찾거나 만들거나 업데이트할 수 있다 그럼 바로 예를 봐보자 예) async function handler(req: NextApiRequest, res: NextApiResponse) { const { email, phone } = req.body; // POST request로 받는 정보 (이메일 또는 핸드폰 번호) let user; //유저 if (email) { user = await client.user.findUnique({ where: { email, }, }); if (user) console.log(user, "user with email"); if (!user) { console.log("did not find.. 코드 정리 (0) Import Path file들을 import 하다보면 path가 너무 복잡해보이는 경우가 자주있다 예) 이렇게 보이는 Path를 심플하게 바꿔줄수있는데 바로 알아보도록 하자 line 17을 보면 paths를 새로 지정해준걸 볼수있다 ./ 로 시작하는 path 모두 다 @/ 로 바꿔주는걸로 세팅을 바꾼거다 이후 다시 파일로 되돌아가면 path가 더 간결해진걸 볼수있다 NextJS (7) _app 만약 모든 페이지에 똑같은 작업을 하고 싶다면 _app 파일에 대해 알아야 한다 _app 파일은 다른 파일들을 렌더링 하기 전에 _app파일을 제일 먼저 렌더링을 한다 그럼 바로 예시를 봐보자 예) 우선 pages folder안에 파일들을 만들어주고 이렇게 _app 파일을 만들어줬다 _app파일은 Component와 pageProps props들을 받는데 Component prop은 프로그램 실행을 할 때 Component props에서 모든 component들을 하나씩 불러와 작업을 한다 예) 예를 들어 프로그램을 실행시키면 _app 파일은 Index component를 불러와 작업을 한다는 뜻 이후 Info component도 불러와 작업시킨다 pageProps는 단순히 각 component에 있는 .. Javascript (6) Repeat Javascript에서 string을 반복해서 출력해야 될 때 repeat() method가 아주 유용하다 그럼 바로 간단한 예시를 보며 어떻게 사용하는지 확인해보자 예) 이렇게 string 값. repeat(반복 횟수)를 넣어준 뒤 실행을 시키면 결과가 잘 나오는 걸 볼 수 있다 Javascript (5) Object.keys vs Object.values Object를 풀어낼 때 object.keys를 사용한다 바로 예시를 봐보자 예) 이렇게 stuff object를 만든 뒤 fruits, countries array들을 만들어주었다 여기서 Object.keys(object 이름) 은 array의 이름을 출력해 주고 array를 출력하려면 Object.values(object 이름을 쓰면 된다 예) 이렇게 Object.values()를 쓰고 실행시킨 뒤 console을 보면 array가 잘 나온 걸 볼 수 있다 그럼 각 이전 1 다음