Express.js在linux服务器上抛出错误:enoint
所以,我一直在编写一个上传脚本(代码如下),我在我的windows机器上使用它,但在我的Linux服务器上,它似乎失败了Express.js在linux服务器上抛出错误:enoint,linux,node.js,express,forever,Linux,Node.js,Express,Forever,所以,我一直在编写一个上传脚本(代码如下),我在我的windows机器上使用它,但在我的Linux服务器上,它似乎失败了 Error: ENOENT, open 'uploads/da5ab67b48ea2deecd25127186017083' 我知道错误是说没有路径/文件,但在尝试重命名文件之前,我会检查文件是否存在 exports.product_files_upload = function (req, res) { if (req.files) { var t
Error: ENOENT, open 'uploads/da5ab67b48ea2deecd25127186017083'
我知道错误是说没有路径/文件,但在尝试重命名文件之前,我会检查文件是否存在
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);
}
};
更新:我正在使用forever运行我的express应用程序,当我停止我的应用程序forever进程并切换到“node app.js”时,问题得到了解决。这不是一个可接受的解决方案。我在想“永远”可能有问题。好吧,我想出来了。我一直在用一个绝对路径在我的linux机器上启动我的应用程序,就像
forever start /path/to/app.js
但当我将cd放入应用程序目录,然后启动应用程序时,它就可以工作了
forever start app.js
好吧,我知道了。我一直在用一个绝对路径在我的linux机器上启动我的应用程序,就像
forever start /path/to/app.js
但当我将cd放入应用程序目录,然后启动应用程序时,它就可以工作了
forever start app.js