Languages
[Edit]
EN

Node.js - read file as text (UTF-8)

3 points
Created by:
Vanessa-Drake
718

In this article, we would like to show you how to read file as text using Node.js.

Quick solution:

or:

Note: to know different text encoding check this article.

 

Practical example

Edit

In this section you can find two examples that shows how to read example file.txt file as text. First example reads file.txt file synchronously and second one asynchronously.

Example file.txt file:

 

Sync mode

Edit

Example index.js file:

Output:

 

Async mode

Edit

Example index.js file:

Output:

 

See also

Edit
  1. Node.js - supported text encoding

  2. Node.js - read files

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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