From 1c1ab074ce730442e37df7ab9835ca91995603a6 Mon Sep 17 00:00:00 2001 From: hippoz Date: Fri, 2 Oct 2020 23:08:12 +0300 Subject: [PATCH] turns out it was deprecated... BRUH --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 61b78f2..9f5a67d 100644 --- a/index.js +++ b/index.js @@ -87,14 +87,16 @@ app.post('/api/upload', (req, res) => { const file = req.files.file; const filepath = `${config.storagePath}/${file.name}`; - fs.exists(filepath, (exists) => { - if (!exists) { + fs.stat(filepath, (err) => { + if(err == null) { + return res.status(400).send('File exists.'); + } else if(err.code === 'ENOENT') { file.mv(filepath, (err) => { if (err) return res.status(500).send(err); res.render('uploaded', { file: { name: file.name } }); }); } else { - return res.status(400).send('File exists.'); + return res.sendStatus(500); } }); });