Skip to content

Instantly share code, notes, and snippets.

@catalinpit
Created June 10, 2021 13:49
Show Gist options
  • Save catalinpit/a8cb6aca75cef8d6ac5043eae9ba22ce to your computer and use it in GitHub Desktop.
Save catalinpit/a8cb6aca75cef8d6ac5043eae9ba22ce to your computer and use it in GitHub Desktop.
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.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!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment