Express.js抛出错误:ENOENT在Linux服务器上

所以,我一直在研究一个上传脚本(代码如下),我已经在我的Windows机器上工作,但在我的Linux服务器上,它似乎失败

Error: ENOENT, open 'uploads/da5ab67b48ea2deecd25127186017083' 

我明白,错误是说没有path/文件,但我尝试文件重命名之前检查文件的存在。

 exports.product_files_upload = function (req, res) { if (req.files) { var tmpArray = []; for(var file in req.files){ console.log(file) if (file){ var splitName = file.split('-'); if (splitName.length > 1) { var username = splitName[0]; var productId = splitName[1]; var index = splitName[2]; } else { return; } } else { return; } //console.log(username) //console.log(productId) var tmp_path = req.files[file].path; console.log(fs.existsSync(tmp_path)) createUserDir(); createProductDirs(username, productId); //console.log(__dirname) var target_path = './public/user_files/'+ username + '/products/'+productId+'/files/' + req.files[file].name, save_path = 'user_files/'+ username + '/products/'+productId+'/files/' + req.files[file].name; if (fs.existsSync(target_path)) { tmpArray.push({exists:true, name:req.files[file].name}); } else { tmpArray.push({ size: req.files[file].size, type: req.files[file].type, name: req.files[file].name, path: save_path, exists:false }); if (fs.existsSync(tmp_path)) { fs.rename(tmp_path, target_path, function(err) { if (err) throw err; // delete the temporary file, so that the explicitly set temporary upload dir does not get filled with unwanted files fs.unlink(tmp_path, function() { if (err) throw err; // res.send(save_path); }); }); } else { tmpArray.push({ size: req.files[file].size, type: req.files[file].type, name: req.files[file].name, path: save_path, exists:false }); } } } res.json(tmpArray); } }; 

更新:我永远用于运行我的快递应用程序,当我永久停止我的应用程序,并切换到只是“节点app.js”的问题是固定的。 这不是一个可接受的修复方法。 我在想可能永远有问题。

好吧,我明白了。 我永远用一个绝对path来启动我的应用程序在我的Linux机器上

 forever start /path/to/app.js 

但是,当我进入应用程序目录,然后启动应用程序的作品。

 forever start app.js