我正在尝试使用NodeJS/ExpressJS 将上传的文件移动/tmp到home目录:
fs.rename('/tmp/xxxxx', '/home/user/xxxxx', function(err){
if (err) res.json(err);
console.log('done renaming');
});
Run Code Online (Sandbox Code Playgroud)
但它没有工作,也没有遇到任何错误.但是,当新的道路也在/tmp,那将是有效的.
我在使用Ubuntu,home是在不同的分区.任何修复?
谢谢
我有一个更新方法,它大约每 16-40 毫秒被调用一次,在里面我有这个代码:
this.fs.writeFile("./data.json", JSON.stringify({
totalPlayersOnline: this.totalPlayersOnline,
previousDay: this.previousDay,
gamesToday: this.gamesToday
}), function (err) {
if (err) {
return console.log(err);
}
});
Run Code Online (Sandbox Code Playgroud)
如果服务器抛出错误,“data.json”文件有时会变为空。我该如何防止?