Close Menu
    Facebook X (Twitter) Instagram
    Oixiesoft
    • Home
    • Services
      • WordPress Malware Removal
      • Fix WordPress Errors
      • WordPress Website Development
    • Articles
    • Contact
    Oixiesoft
    Home»Tutorial»Node.js»Node.js File System Module
    Node.js

    Node.js File System Module

    Editorial StaffBy Editorial StaffUpdated:October 14, 2022No Comments1 Min Read
    Share
    Facebook Twitter LinkedIn Pinterest Email

    What is a Module in Node.js?

    You can consider Node.js modules to be the exact as JavaScript libraries. The bunch of functions are collected in single or multiple JavaScript files which you can include in your application.

    Using require() method to include Node File System (fs) module:

    var fs = require('fs');

    The Node fs module is responsible for all the asynchronous or synchronous file I/O procedures.

    Common use for the File System module:

    • Read files
    • Delete files
    • Rename files
    • Create files
    • Update files

    Read Files

    You can use the fs.readFile() method to read files asynchronously.

    Example: Read File

    Let us assume we have the testfile.html HTML file

    var fs = require('fs');
    
    fs.readFile('testfile.html', function (err, data) {
                        if (err) throw err;
    
        console.log(data);
    });
    

    Delete Files

    To delete any file with the FS module, apply the fs.unlink() method.
    This method deletes the selected file:

    Example
    Delete “testdemo.html”:

    var fs = require('fs');
    
    fs.unlink('testdemo.html', function () {
        
        console.log('write operation complete.');
    
    });
    
    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Tumblr Email
    Editorial Staff

    Related Posts

    CodeIgniter vs Laravel: A Detailed Side-by-Side Comparison

    Python Arrays

    Python Lambda

    • Nodejs Introduction
    • Download and Install Node.js
    • Node.js Modules
    • Node.js NPM
    • Node.js Console/REPL
    • Node.js File System Module
    Services
    • Web Development
    • Mobile Application Development
    • WordPress Malware Removal Service
    • Website Design
    • WordPress Development
    • Magento Development
    • Shopify Development
    • SEO Services
    Blog
    • How to Fix the Error Establishing a Database Connection
    • Ping List WordPress
    • How To Fix Japanese Keyword Hack
    • How to remove Malware from WordPress
    Hire Developers
    • Hire WordPress Developer
    • Hire Shopify Developer
    Contact Info
    • Oixiesoft Technologies
      A-40, Block A, I thum Tower, Sector 62, Noida
    • [email protected]
    • Privacy Policy
    • About Us
    • Contact Us
    © 2025 OixieSoft Technologies

    Type above and press Enter to search. Press Esc to cancel.