文件结构图
![](https://i-blog.csdnimg.cn/blog_migrate/847240afaa6ab0b75bc17f5da8cc877d.png)
{
"next":"b.json",
"msg":"this is a"
}
{
"next":"c.json",
"msg":"this is b"
}
{
"next":"null",
"msg":"this is c"
}
上一层
const fs=require('fs')
const path=require('path')
//用jpromise获取文件内容
function getFileContent(filName){
const promise= new Promise((resolve, reject)=>{
const fullFileName=path.resolve(__dirname,'files',filName)
fs.readFile(fullFileName,(err,data)=>{
if(err){
reject(err)
return
}
resolve(
JSON.parse(data.toString())
)
})
})
return promise
}
getFileContent('a.json').then(aData=>{
console.log("a data", aData)
return getFileContent(aData.next)
}).then(bData=>{
console.log("b data", bData)
return getFileContent(bData.next)
}).then(cData=>{
console.log("c data", cData)
})