[NodeJS] FileSystem 파일 간단 읽기 - fs 사용 모듈 : fs (FileSystem) Test File : ./readfile.txt Source // fs 모듈 로드 const fs = require("fs"); // readfile.txt 파일을 utf-8 형식으로 동기화 해서 추출 const data = fs.readFileSync("readfile.txt", "utf-8"); // 출력 console.log(data); Result 개발 창고/NodeJS 2024.01.19
[FS] 파일 복사 // filecopy.js const fs = require('fs'); (async () => { fs.copyFile('origin.txt', 'copied.txt', err => { if(err) throw err; console.log('origin.txt파일이 copied.txt파일로 복사되었습니다.'); }); })(); fs.copyFile("원본파일", "복사될파일", callback함수) 만약 아래와 같이 origin.txt파일이 실행하려는 파일 filecopy.js와 같은 폴더에 존재한다면 아래 명령어를 실행하면 console.log에서 적어둔 message가 출력되면서 아래와 같이 copied.txt파일이 생성됨을 확인할 수 있습니다. callback은 굳이 필요 없는 경우 생략해도 .. 개발 창고/NodeJS 2023.02.20