From fcb84e9d6a57a06175af58200fe1a70aae7122af Mon Sep 17 00:00:00 2001 From: Vivek Date: Sun, 26 Jun 2022 13:42:18 +0530 Subject: [PATCH] CURD Operations --- apple.txt | 1 - curd.js | 30 ++++++++++++++++++++++++++++++ curd/fruit.txt | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) delete mode 100644 apple.txt create mode 100644 curd.js create mode 100644 curd/fruit.txt diff --git a/apple.txt b/apple.txt deleted file mode 100644 index bca29ed..0000000 --- a/apple.txt +++ /dev/null @@ -1 +0,0 @@ -this is fruit \ No newline at end of file diff --git a/curd.js b/curd.js new file mode 100644 index 0000000..3c91f10 --- /dev/null +++ b/curd.js @@ -0,0 +1,30 @@ +const fs = require('fs'); +const path = require('path'); +const dirPath = path.join(__dirname , 'curd'); + +const filePath = `${dirPath}/hello.txt`; + +// Creating a file +fs.writeFileSync(filePath , 'this is a simple text'); + +// reading the file +fs.readFile(filePath , "utf8" , (err , item) => { + console.log(item); +}) + +// appending a file +fs.appendFile(filePath , ' and this an apple.txt file' , (err) => { + if(!err) + console.log('file is updated'); +} ); + +//renaming the file +fs.rename(filePath , `${dirPath}/fruit.txt` , (err) => { + if(!err) + console.log('file name is updated') +}); + +// deleting the file + +//fs.unlinkSync(`${dirPath}/fruit.txt`); + diff --git a/curd/fruit.txt b/curd/fruit.txt new file mode 100644 index 0000000..f94117d --- /dev/null +++ b/curd/fruit.txt @@ -0,0 +1 @@ +this is a simple text and this an apple.txt file \ No newline at end of file