๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
JavaScript/Node.js

[Node.js-์ƒํ™œ์ฝ”๋”ฉ] ๋™๊ธฐ์™€ ๋น„๋™๊ธฐ 2

by ์ฝ”๋”ฉํ•˜๋Š” ๋ถ•์–ด 2021. 1. 29.
๋ฐ˜์‘ํ˜•

[์ถœ์ฒ˜-Youtube ์ƒํ™œ์ฝ”๋”ฉ]

https://www.youtube.com/watch?v=7woGFlMhSgk&list=PLuHgQVnccGMA9QQX5wqj6ThK7t2tsGxjm&index=37

 

 

syntax/sample.txt

B

 

 

syntax/sync.js

var fs = require('fs');
 
/*
//readFileSync
console.log('A');
var result = fs.readFileSync('syntax/sample.txt', 'utf8');
console.log(result);
console.log('C');
*/
 
 
console.log('A');
fs.readFile('syntax/sample.txt', 'utf8', function(err, result){  // ํ•จ์ˆ˜๋ฅผ 3๋ฒˆ์งธ ์ธ์ž๋กœ ์คŒ
    console.log(result);
});
console.log('C');

 

 

readFileSync์€ return๊ฐ’์„ ์ฃผ๊ณ 

readFile๋Š” ๋ฆฌํ„ด ๊ฐ’์ด ์—†์Œ (๋Œ€์‹  ํ•จ์ˆ˜๋ฅผ 3๋ฒˆ์งธ ์ธ์ž๋กœ ์ค˜์•ผ ํ•จ)

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€