Skip to content

Instantly share code, notes, and snippets.

@Victor-Villacis
Created September 13, 2021 19:40
Show Gist options
  • Save Victor-Villacis/1083ec4a4804c41e3db78c1754a6d276 to your computer and use it in GitHub Desktop.
Save Victor-Villacis/1083ec4a4804c41e3db78c1754a6d276 to your computer and use it in GitHub Desktop.
'use strict'
//read, write and delete file using sync methodss.
const fs = require('fs');
const data = fs.readFileSync('target.txt');
fs.writeFileSync("turbo.txt", `I am from target.txt: ${data} this is take 2`);
process.stdout.write("\nFrom process stdout: " + data.toString());
console.log("\nFrom console log: " + data.toString())
const targetTxt = fs.readFileSync('turbo.txt');
process.stdout.write("\nFrom process stdout2: " + targetTxt.toString());
console.log("\nFrom console log2: " + targetTxt.toString())
fs.copyFileSync("./turbo.txt", "./turbo2.txt")
setTimeout(() => {
fs.unlinkSync("./turbo2.txt")
}, 3000)
const targetTxt2 = fs.readFileSync('./turbo2.txt')
process.stdout.write(`\n${targetTxt2}: This file will be deleted`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment