相关疑难解决方法(0)

在ExpressJS/NodeJS中移动文件

我正在尝试使用NodeJS/ExpressJS 将上传的文件移动/tmphome目录:

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是在不同的分区.任何修复?

谢谢

ubuntu file-upload file node.js express

10
推荐指数
2
解决办法
1万
查看次数

Node.js fs.writeFile() 清空文件

我有一个更新方法,它大约每 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”文件有时会变为空。我该如何防止?

javascript fs node.js

2
推荐指数
1
解决办法
3495
查看次数

标签 统计

node.js ×2

express ×1

file ×1

file-upload ×1

fs ×1

javascript ×1

ubuntu ×1