본문 바로가기

전체 글

(51)
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 (1) Module It's always better to keep your codes simple. In order to keep the code clean, it's important to create modules (files) to separate things in parts. Let's see some examples to see what I mean by keeping code clean Ex. To make this code simpler using modules, we can put them in separate files and call elements that are needed Ex. As you can see in the example, I separated my code in three separat..
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.
TailwindCSS(0) 시작하기 우선 tailwindcss를 다운하자 npm i -D tailwindcss postcss autoprefixer npx tailwindcss init -p 다운 이후 tailwind.config.js 파일에서 content를 설정해줘야 하는데 여기서는 어디서 tailwindcss를 사용할 건지 알려줘야 한다 여기서 필자는 모든 pages 폴더 안에 js jsx ts tsx 파일들 모두 tailwindcss를 적용시킬 거 기 때문에 line 4에 설정을 해주었다 line 5에서는 pages 폴더와 비슷하게 components 폴더 안에 모두 적용시킬 거 기 때문에 설정을 또 해준걸 볼 수 있다 마지막으로 styles/globals.css 파일로 가서 이렇게 tailwind 설정을 마지막으로 해주면 끝난다
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..
ES6 (1) If Else in an Object Object 안에서 if else를 사용하는 es6 문법에 대해 알아보자 예) async function handler(req: NextApiRequest, res: NextApiResponse) { const { email, phone } = req.body; // 유저가 로그인 할시 이메일 또는 폰 번호로 로그인을 시도함 const user = await client.user.upsert({ where: { ...(phone && { phone: +phone }), // if (phone) {phone: +phone} 으로 쓴다 ...(email && { email }), // if (email) {email} }, create: { name: "Anonymous", ...(phone && { pho..
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가 더 간결해진걸 볼수있다