fs
- 파일을 읽고 쓰는 기능을 제공하는 Node.js의 파일 시스템 모듈
fs.readdirSync(path[, options]) - 동기 처리
- 디렉토리의 내용을 읽어오는 함수
- 디렉토리 안의 파일명들을 담은 배열을 반환
const fileNames = fs.readdirSync(postsDirectory);
fs.readdir(path[, options], callback) - 비동기 처리
fs.readFileSync(path, options)
- 경로를 전달해 파일 안의 내용을 읽어오는 함수
const fileContents = fs.readFileSync(fullPath, 'utf8');
path
path.join(경로, .. )
- 여러 인자를 넣으면 하나의 경로로 합쳐준다.
- 상대경로 처리
const postsDirectory = path.join(process.cwd(), 'posts');
path.resolve(경로, .. )
- path.join()과 비슷한 내용
- 절대경로로 처리
filename, dirname, process.cwd()
__filename
- file 명을 포함한 절대 경로
ex) /Users/lsonghee/Desktop/fast campus/react/create-nextjs-app/lib/post.ts
__dirname
- file 명을 제외한 절대 경로
ex) /Users/lsonghee/Desktop/fast campus/react/create-nextjs-app/lib
process.cwd()
- node명령을 호출한 작업 디렉토리의 절대 경로, 현재 작업경로