CURD operation in Node JS Folder

 // decleration of vairables here


const fs=require('fs');
const path=require('path');
const dirPath=path.join(__dirname,'CURD');
const filePath=`${dirPath}/apple.txt`;

// now we have created a folder

fs.writeFileSync(filePath,"i am working in Stuvalley Technology in Gurugram");
fs.readFile(filePath,'utf-8',(err,item)=>{
    console.log(item);
});


// after that we have add some text in created file in side

fs.appendFile(filePath,' and my role is software developer intern',(err)=>
{
    if(!err) console.log("file is Updated Now");
});

// now we have rename the file name

fs.rename(filePath,`${dirPath}/xyz.txt`,(err)=>
{
    if(!err) console.log("file is renamed Now");
});

// and finally we have remove the file
fs.unlinkSync(`${dirPath}/xyz.txt`)

Post a Comment

0 Comments