Page 123 - Nodejs 교과서 개정2판
P. 123

console.log(data)ܳ ೮؊פ Bufferۄח ੉࢚ೠ Ѫ੉ ୹۱ؾפ׮  Ӓېࢲ EBUBী toString()ਸ ࠢৈࢲ ۽Ӓ

         ܳ ନ঻؊פ ઁ؀۽ ޙ੗ৌ੉ ୹۱ؾפ׮  readFile੄ Ѿҗޛ਷ ߡಌ Buffer ۄח ഋधਵ۽ ઁҕؾפ׮  ૑Ә਷
         ױࣽ൤ ߡಌܳ ݫݽܻ੄ ؘ੉ఠۄҊ ࢤпೞݶ ؾפ׮       ੺ীࢲ ੗ࣁೞѱ ࢸݺ೤פ׮  ߡಌח ࢎۈ੉ ੍ਸ ࣻ

         ੓ח ഋध੉ ইפ޲۽ toStringਸ ࢎਊ೧ ޙ੗ৌ۽ ߸ജ೮णפ׮

         GTח ӝࠄ੸ਵ۽ ௒ߔ ഋध੄ ݽٕ੉޲۽ पޖীࢲ ࢎਊೞӝо ࠛಞ೤פ׮  ٮۄࢲ GT ݽٕਸ ೐۽޷झ ഋधਵ۽

         ߄Լ઱ח ߑߨਸ ࢎਊ೤פ׮

          readFilePromise.js

           const	fs	=	require('fs').promises;


           fs.readFile('./readme.txt')
           		.then((data)	=>	{
           				console.log(data);
           				console.log(data.toString());
           		})
           		.catch((err)	=>	{
           				console.error(err);
           		});




         GT ݽٕীࢲ promise ࣘࢿਸ ࠛ۞য়ݶ ೐۽޷झ ӝ߈੄ GT ݽٕਸ ࢎਊೡ ࣻ ੓ѱ ؾפ׮  খਵ۽ח ೐۽޷झ ӝ
         ߈੄ GT ݽٕਸ ࢎਊೞѷणפ׮

         ੉ߣীח ౵ੌਸ ٜ݅যࠁѷणפ׮


          writeFile.js
           const	fs	=	require('fs').promises;


           fs.writeFile('./writeme.txt',	'글이	입력됩니다')
           .then(()	=>	{
           		return	fs.readFile('./writeme.txt');
           })
           .then((data)	=>	{
           		console.log(data.toString());
           })
           .catch((err)	=>	{
           		console.error(err);
           });





         writeFile ݫࢲ٘ী ࢤࢿؼ ౵ੌ੄ ҃۽৬ ղਊਸ ੑ۱೤פ׮  ب઺ী ী۞о ߊࢤೞ૑ ঋও׮ݶ э਷ ಫ؊ ղ
         ী writeme txtо ࢤࢿغ঻ਸ Ѫੑפ׮  ૒੽ ৌযࠊب غ૑݅  ౵ੌ दझమਸ ҕࠗೞח ઺੉޲۽ readFile ݫ
   118   119   120   121   122   123   124   125   126   127   128