Node.js File System (fs) Module
The fs module in Node.js is used
to work with files and folders.
Example
const fs = require("fs");
fs.writeFileSync("example.txt", "Hello from Node.js!");
console.log("File created successfully.");
Output:
File created successfully.
A file named example.txt is created.
Common fs Methods
- writeFileSync() - Creates/writes a file
- readFileSync() - Reads a file
- appendFileSync() - Adds content to a file
- unlinkSync() - Deletes a file
↠Back to Home