I want to rename a file which I am getting as incoming from client . I am using node js , express , path , fs to perform operations .
Here is the node js function where I want to rename the incoming file :
app.post('/results/upload',(request,response)=>{
const resultFile = request.files.file;
const fileInfo="result"
fs.rename(`${resultFile.name}`, `${fileInfo}`, (err) => {
if (err) throw err;
console.log('Rename complete!');
});
So I am getting error as no such file or directory. its because of the renaming part , so please tell me how to rename the incoming file in node js
This is the log file of the resultFile:
`{
name: 'Modern React with Redux.pdf',
data: <Buffer 25 50 44 46 2d 31 2e 32 0a 25 20 63 72 65 61 74 65 64 20 62 79 20 50 49 4c 20 50 44 46 20 64 72 69 76 65 72 20 30 2e 34 0a 31 20 30 20 6f 62 6a
0a 3c ... 1158630 more bytes>,
size: 1158680,
encoding: '7bit',
tempFilePath: '',
truncated: false,
mimetype: 'application/pdf',
md5: '501b04f153114b7342236a2a185a7ff7',
mv: [Function: mv]
}`
resultFilethat you want to rename? Looks like right now you are just specifying the name only and it likely is not in the default searched directory. YourresultDirectoryvariable is also unused. Perhaps you want to include that in the destination path as well.resultFilenot have apathproperty?console.log(resultFile)in your question;