Using the "fs" package, we can easily achieve this output:

Read a text file using Node.js?


    var fs = require('fs');

    try {  
        var data = fs.readFileSync('file.txt', 'utf8');
        console.log(data.toString());    
    } catch(e) {
        console.log('Error:', e.stack);
    }

0
2023-06-29
Node.js
0
0
2023-06-29
Node.js
0
0

Contact Us

If you have any inquiries or feedback, please don't hesitate to reach out to us at [email protected]. We will respond to your request as soon as possible. Thank you very much for your interest!

Country profiles