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

 
          
               BTZOD BXBJU

         ֢٘     ߡ੹ࠗఠ ૑ਗغח ӝמੑפ׮  &4    ীࢲ ୶оغ঻ਵݴ  ঌইفݶ ੿݈ ಞܻೠ ӝמੑפ׮  ౠ൤ ֢

         ٘୊ۢ ࠺زӝ ਤ઱۽ ೐۽Ӓې߁ਸ ೧ঠ ೡ ٸ ب਑੉ ݆੉ ؾפ׮

         ೐۽޷झо ௒ߔ ૑ৠਸ ೧Ѿ೮׮૑݅  ৈ੹൤ ௏٘о ੢ട೤פ׮  thenҗ catchо ҅ࣘ ߈ࠂغӝ ٸޙੑפ׮

         async await ޙߨ਷ ೐۽޷झܳ ࢎਊೠ ௏٘ܳ ೠ ߣ ؊ ӭՔೞѱ ઴ੑפ׮

              ੺੄ ೐۽޷झ ௏٘ܳ ׮द ೠ ߣ ࠁѷणפ׮




           function	findAndSaveUser(Users)	{
           		Users.findOne({})
           				.then((user)	=>	{
           						user.name	=	'zero';
           						return	user.save();
           				})
           				.then((user)	=>	{
           						return	Users.findOne({	gender:	'm'	});
           				})
           				.then((user)	=>	{
           						//	생략
           				})
           				.catch(err	=>	{
           						console.error(err);
           				});
           }




         ௒ߔҗ ׮ܰѱ ௏٘੄ Ө੉о Өয૑૓ ঋ૑݅  ௏٘ח ৈ੹൤ Ӥפ׮  BTZOD await ޙߨਸ ࢎਊೞݶ ׮਺җ э

         ੉ ߄Ե ࣻ ੓णפ׮  async	function੉ۄח Ѫ੉ ୶оغ঻णפ׮




           async	function	findAndSaveUser(Users)	{
           		let	user	=	await	Users.findOne({});
           		user.name	=	'zero';
           		user	=	await	user.save();
           		user	=	await	Users.findOne({	gender:	'm'	});
           		//	생략
           }




         ֥ۄ਎ ੿ب۽ ௏٘о ૣই઎णפ׮  ೣࣻ ࢶ঱ࠗܳ ੌ߈ ೣࣻ ؀न async	functionਵ۽ Ү୓ೠ റ  ೐۽޷झ
   62   63   64   65   66   67   68   69   70   71   72