-
-
Save catalinpit/7c8d40db53dea9e6831f9ee89d92475c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
fs.writeFile('content.txt', 'This is my first file!', (err) => { | |
if (err) { | |
throw err; | |
}; | |
process.stdout.write('File created successfully!'); | |
}); | |
const filePath = path.join(process.cwd(), 'content.txt'); | |
fs.readFile(filePath, (error, content) => { | |
if (error) throw error; | |
process.stdout.write(content); | |
}); | |
// fs.unlink(filePath, (error) => { | |
// if (error) throw error; | |
// console.log('File deleted!') | |
// }); | |
fs.readdir(process.cwd(), (error, files) => { | |
if (error) throw error; | |
console.log(files); | |
}); | |
fs.mkdir(`${process.cwd()}/myFolder/secondFolder`, { recursive: true }, (err) => { | |
if (err) throw err; | |
console.log('Folder created successfully!'); | |
}); | |
// fs.rmdir(`${process.cwd()}/myFolder/`, { recursive: true }, (err) => { | |
// if (err) throw err; | |
// console.log('Folder/s removed successfully!'); | |
// }); | |
fs.rename(`${process.cwd()}/myFolder/secondFolder`, `${process.cwd()}/myFolder/newFolder`, (err) => { | |
if (err) throw err; | |
console.log('Directory renamed!'); | |
}); | |
fs.appendFile(filePath, '\nNew data to be added!', (err) => { | |
if (err) throw err; | |
console.log('New content added!'); | |
}); | |
fs.rename(`${process.cwd()}/content.txt`, `${process.cwd()}/newFile.txt`, (err) => { | |
if (err) throw err; | |
console.log('File renamed!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment