fs


1. Read a File Synchronously

const fs = require('fs');

const data = fs.readFileSync('file.txt', 'utf8');
console.log(data);

2. Read a File Asynchronously

const fs = require('fs');

fs.readFile('file.txt', 'utf8', (err, data) => {
  if (err) throw err;
  console.log(data);
});

3. Write a File Synchronously

const fs = require('fs');

fs.writeFileSync('file.txt', 'Hello, world!', 'utf8');

4. Write a File Asynchronously

const fs = require('fs');

fs.writeFile('file.txt', 'Hello, world!', 'utf8', (err) => {
  if (err) throw err;
});

5. Append to a File Synchronously

6. Append to a File Asynchronously

7. Rename a File Synchronously

8. Rename a File Asynchronously

9. Copy a File Synchronously

10. Copy a File Asynchronously

11. Delete a File Synchronously

12. Delete a File Asynchronously

13. Create a Directory Synchronously

14. Create a Directory Asynchronously

15. Remove a Directory Synchronously

16. Remove a Directory Asynchronously

17. Read a Directory Synchronously

18. Read a Directory Asynchronously

19. Check if a File Exists Synchronously

20. Check if a File Exists Asynchronously

21. Get File Metadata Synchronously

22. Get File Metadata Asynchronously

23. Create a File Stream for Reading

24. Create a File Stream for Writing

25. Pipe a File Stream

26. Watch a File for Changes

27. Unwatch a File

28. Get File Size Synchronously

29. Get File Size Asynchronously

30. Get File Modification Date Synchronously

31. Get File Modification Date Asynchronously

32. Set File Modification Date Synchronously

33. Set File Modification Date Asynchronously

34. Get File Owner Synchronously

35. Get File Owner Asynchronously

36. Set File Owner Synchronously

37. Set File Owner Asynchronously