ファイルの内容を取得することを約束

ファイル構造図

{
     " "" b.json " " MSG "" これは" 
}
a.json
{
     " "" c.json " " MSG "" これはBです" 
}
b.json
{
     " 次へ"" ヌル" " MSG "" これはCです" 
}
c.json

 

1つ上のレベル

CONST FS =(必要' FSを' CONST =パス(必要' パス' 


// jpromiseでファイルの内容を取得

関数getFileContent(filName){

      constの   約束= 新しい約束((解決、拒否)=> {
         
        constの fullFileName = path.resolve(__ dirnameは、' ファイル' 、filName)

         fs.readFile(fullFileName、(ERR、データ) => {

              もし(ERR){
                  拒否(ERR)
                  リターン
              }
              決意(
                  JSON.parse(data.toString())
         })
            
      })
      リターンの約束
}

getFileContent(' a.json ').then(ADATA => {
     console.log(" データ" 、ADATA)
      リターンgetFileContent(aData.next)
})。次に、(BDATA => {
    console.log(" Bデータ" 、BDATA)
     リターンgetFileContent(bData.next)
})。次に、(CDATA => {
    console.log(" Cデータ" 、CDATA)
})

 

おすすめ

転載: www.cnblogs.com/hack-ing/p/11994412.html