Skip to content

Instantly share code, notes, and snippets.

@catalinpit

catalinpit/deleteFile.js Secret

Created Jun 10, 2021
Embed
What would you like to do?
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!')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment