파일/폴더 생성, 삭제, 읽기, 쓰기 가능
웹 브라우저에서는 제한적이었으나 노드는 권한을 가지고 있다.
readFile은 비동기적으로 동작한다.
const fs = require('fs');
fs.readFile('파일',(err,data) => {
if(err) {
throw err;
}
console.log(data); // 바이너리 코드가 나온다.
console.log(data.toString())
}
const fs = require('fs');
fs.writeFile('파일','내용')
.then(() => {
})
.catch((err) => {
throw err;
});
const fs = require("fs");
let data = fs. readFileSync('파일');
console.log('1',data.toString());data = fs. readFileSync('파일');
console.log('2',data.toString());data = fs. readFileSync('파일');
console.log('3',data.toString());data = fs. readFileSync('파일');
console.log('4',data.toString());


실행시 비동기 호출들은 백그라운드로 가서 실행되기 때문에 어떻게 실행될지는 OS만 알 수 있다.

비동기 호출을 했지만 순서대로 실행되는 것을 볼 수 있다. 하지만 보는것 처럼 콜백 헬이 발생하였고 promises를 이용해서 한다면 콜백 헬을 해결할 수 있다.
node는 fs 파일을 읽어 올 때는 readFile은 비동기 처리가 되지만 콜백 헬에 걸릴 수 있다. 콜백 헬을 해결하기 위해 promises를 지원한다