Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
557 views
in Technique[技术] by (71.8m points)

为什么node.js删除item.json删不掉,但是里面的数据会清掉,而且关掉服务的时候,又会自动删掉item.json?

exports.pushdata = function(req,res){
var isDelete = false;
fs.readFile('./uploads/item.json','utf8',function(err,data){

if(err) throw err;
var json = JSON.parse(data);
db.delete("content",{},function(err,result){
  if(err){
  }else{
    isDelete = true;
  }
})
db.insert("content",json,function(err,result){
  if(err){
    res.send({
      "msg":"请联系技术人员",
    });
    return false;
  }else{
    fs.readdir("./uploads",function(err,files){
      var length = 0;
      var fileslength =files.length;
      if(err){
        throw err;
       }
      for(var i=0;i<fileslength;i++){
        console.log(files[i]);
        fs.unlink("./uploads/"+files[i],function(err){
           if(err){
             console.log(err);
           }else{
            i++;
            console.log("删除成功");
          }
        })
      }
    });
    if(isDelete){
      res.send({
        "msg":"原有数据库已删除,生成新的数据"
      })
    }else{
      res.send({
        "msg":"输入成功",
      })             
    }
 
  }
})

});
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...