Languages
[Edit]
EN

Node.js - read text file example

0 points
Created by:
Vanessa-Drake
418

In this article, we would like to show you how to read text files in Node.js.

Note: 
Check out this article to learn more about reading files in Node.js.

Practical example

textFile.txt

First line.
Second line.

Code:

const fs = require('fs');

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

Output: 

First line.
Second line.

See also

  1. Node.js - read files

Node.js - file system module

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join