Since Node.js v0.12 and as of Node.js v4.0.0, there is a stable readline core module. Here's the easiest way to read lines from a file, without any external modules:

const fs = require('fs');
const readline = require('readline');

async function processLineByLine() {
  const fileStream = fs.createReadStream('input.txt');

  const rl = readline.createInterface({
    input: fileStream,
    crlfDelay: Infinity
  });
  // Note: we use the crlfDelay option to recognize all instances of CR LF
  // ('\r\n') in input.txt as a single line break.

  for await (const line of rl) {
    // Each line in input.txt will be successively available here as `line`.
    console.log(`Line from file: ${line}`);
  }
}

processLineByLine();

Or alternatively:

var lineReader = require('readline').createInterface({
  input: require('fs').createReadStream('file.in')
});

lineReader.on('line', function (line) {
  console.log('Line from file:', line);
});

lineReader.on('close', function () {
    console.log('all done, son');
});

The last line is read correctly (as of Node v0.12 or later), even if there is no final \n.

UPDATE: this example has been added to Node's API official documentation.

Answer from Dan Dascalescu on Stack Overflow
🌐
Node.js
nodejs.org › en › learn › manipulating-files › reading-files-with-nodejs
Node.js — Reading files with Node.js
Collecting code coverage in Node.js · The simplest way to read a file in Node.js is to use the fs.readFile() method, passing it the file path, encoding and a callback function that will be called with the file data (and the error): CJSESM · ...
Top answer
1 of 16
1152

Since Node.js v0.12 and as of Node.js v4.0.0, there is a stable readline core module. Here's the easiest way to read lines from a file, without any external modules:

const fs = require('fs');
const readline = require('readline');

async function processLineByLine() {
  const fileStream = fs.createReadStream('input.txt');

  const rl = readline.createInterface({
    input: fileStream,
    crlfDelay: Infinity
  });
  // Note: we use the crlfDelay option to recognize all instances of CR LF
  // ('\r\n') in input.txt as a single line break.

  for await (const line of rl) {
    // Each line in input.txt will be successively available here as `line`.
    console.log(`Line from file: ${line}`);
  }
}

processLineByLine();

Or alternatively:

var lineReader = require('readline').createInterface({
  input: require('fs').createReadStream('file.in')
});

lineReader.on('line', function (line) {
  console.log('Line from file:', line);
});

lineReader.on('close', function () {
    console.log('all done, son');
});

The last line is read correctly (as of Node v0.12 or later), even if there is no final \n.

UPDATE: this example has been added to Node's API official documentation.

2 of 16
180

For such a simple operation there shouldn't be any dependency on third-party modules. Go easy.

var fs = require('fs'),
    readline = require('readline');

var rd = readline.createInterface({
    input: fs.createReadStream('/path/to/file'),
    output: process.stdout,
    console: false
});

rd.on('line', function(line) {
    console.log(line);
});

rd.on('close', function() {
    console.log('all done, son');
});
Discussions

Read a file in Node.js - Stack Overflow
I'm quite puzzled with reading files in Node.js. More on stackoverflow.com
🌐 stackoverflow.com
How to read a .node file? Extremely new to coding and all
A .node file is a compiled native add-on https://nodejs.org/api/addons.html You can't (easily) read them. But you can probably find the source code somewhere. More on reddit.com
🌐 r/node
11
0
October 15, 2024
streaming a large json object to a file to avoid memory allocation error

Well, JSON.stringify and JSON.parse are synchronous methods that unfortunately you can't pipe to and from. Like u/nissen2 suggests, you'll find some modules out there that will provide you what you're looking for.

Ah, I think I got it. Is there a way to permanently increase the amount of memory that node has access to? Thx.

While this may solve your problem in the mean time, I wouldn't suggest simply allocating more memory (especially with a huge JSON object.)

More on reddit.com
🌐 r/node
16
0
October 10, 2014
skipFiles has "node_mobules" yet a source map is being searched for in the Typescript library folder
Well, does it actually say "node_mobules"? More on reddit.com
🌐 r/vscode
2
1
December 2, 2019
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › node-js-fs-readfile-method
Node JS fs.readFile() Method - GeeksforGeeks
July 12, 2025 - The method does not return a value. Instead, it invokes the provided callback function with the file's contents or an error. ​In Node.js, there are two primary methods for reading files: fs.readFile() and fs.readFileSync().
🌐
Node.js
nodejs.org › api › fs.html
File system | Node.js v25.8.1 Documentation
An example of reading a package.json file located in the same directory of the running code: import { readFile } from 'node:fs/promises'; try { const filePath = new URL('./package.json', import.meta.url); const contents = await readFile(filePath, { encoding: 'utf8' }); console.log(contents); ...
🌐
Honeybadger
honeybadger.io › blog › file-operations-node
File operations in Node.js - Honeybadger Developer Blog
February 27, 2024 - Node.js provides a built-in fs module that allows us to perform various file operations. Whether it's reading from or writing to files, handling different file formats, or managing directories, Node.js offers versatile functionalities to interact with the file system.
Find elsewhere
🌐
W3Schools
w3schools.com › nodejs › nodejs_filesystem.asp
Node.js File System Module
Best Practice: Always specify the character encoding (like 'utf8') when reading text files to get a string instead of a Buffer. Node.js provides several methods for creating and writing to files.
🌐
Medium
medium.com › @dalaidunc › fs-readfile-vs-streams-to-read-text-files-in-node-js-5dd0710c80ea
fs.readFile vs streams to read text files in node.js | by Duncan Grant | Medium
August 22, 2017 - The de facto standard of reading text files in node.js is to use fs.readFile(filename, “utf8"). It’s quick and simple to write code using…
🌐
freeCodeCamp
freecodecamp.org › news › how-to-read-and-write-files-with-nodejs
How to Read and Write Files with Node.js
August 19, 2024 - So you should understand how to read and write files. Files are the backbone of data storage. Node.js provides a powerful 'fs' (file system) module to interact with these files seamlessly. Let's assume I want to read a JSON file in Node.js.
🌐
Nodejsdesignpatterns
nodejsdesignpatterns.com › blog › reading-writing-files-nodejs
Reading and Writing Files in Node.js - The Complete Modern Guide
October 12, 2025 - Learn the modern way to read and write files in Node.js using promises, streams, and file handles. Master memory-efficient file operations for production applications.
Authors   Mario CasciaroLuciano Mammino
Published   2024
Pages   660
Rating: 4.6 ​ - ​ 780 votes
🌐
Geshan
geshan.com.np › blog › 2021 › 10 › nodejs-read-file-line-by-line
4 ways to read file line by line in Node.js
October 8, 2021 - Learn how to read file line by line in Node.js with sync and async methods using native and NPM modules.
🌐
Memberstack
memberstack.com › home › blog › product › the ultimate guide to reading files in node.js
The Ultimate Guide to Reading Files in Node.js | Memberstack
March 23, 2022 - In the example provided above, we used the fs.createWriteStream() function to create a file stream that allows us to write raw data to this file, and then we used Node.js' built-in https package to send a request to a sample image hosted on Imgur. After that, we piped the result from our request to our file, so when you run the code above, the image file from our remote URL is downloaded as a new file — image.jpg — and saved on our local machine. We can read JSON files following the same process we did for reading a .txt and the .html file in our previous examples.
🌐
Code Maven
code-maven.com › reading-a-file-with-nodejs
Reading a file with Node.js - blocking and non-blocking
For example to read the content of a file. The "normal" way in Node.js is probably to read in the content of a file in a non-blocking, asynchronous way. That is, to tell Node to read in the file, and then to get a callback when the file-reading has been finished.
🌐
Futurestud.io
futurestud.io › tutorials › node-js-read-file-content-as-string
Node.js — Read File Content as String
July 29, 2021 - This package comes with a handy content(path) method reading and returning the content of the given file path as a string: const Fs = require('@supercharge/filesystem') const text = await Fs.content('./existing-file.txt') // 'Hello Marcus. Dude, you look super sharp today :)' ... Get your weekly push notification about new and trending Future Studio content and recent platform enhancements ... Marcus is a fullstack JS developer. He’s passionate about the hapi framework for Node.js and loves to build web apps and APIs.
🌐
CodeSignal
codesignal.com › learn › courses › fundamentals-of-text-data-manipulation-in-js › lessons › reading-files-line-by-line-in-javascript-using-nodejs
Reading Files Line-by-Line in JavaScript Using Node.js
In JavaScript, particularly when using Node.js, we use the fs module to handle file operations. To open a file and read its contents, we'll make use of the fs.readFileSync() function. This allows us to read the entire file into a string.
🌐
Mitchellmudd
mitchellmudd.dev › blog › read-text-file-nodejs
Read a text file with Node JS to get input from Advent of Code problems | Hallo, I'm Mitchell Mudd!
December 3, 2022 - // GET FILE INPUT const fs = require('fs'); function readFile(filePath) { try { const data = fs.readFileSync(filePath); return data.toString(); } catch (error) { console.error(`Got an error trying to read the file: ${error.message}`); } } const adventOfCodeInput = readFile('./day3/day3Input.txt'); // END OF GET FILE INPUT
🌐
Medium
medium.com › @AnaghTechnologies › understanding-fs-readfile-in-node-js-d49eb8a268ba
Understanding fs.readFile() in Node.js | by Anagh Technologies | Medium
September 6, 2024 - fs.readFile() is a fundamental Node.js function used to read data from a file asynchronously. This asynchronous nature allows your application to continue executing other tasks while the file is being read, preventing blocking operations.
🌐
Medium
medium.com › hail-trace › effortlessly-reading-files-line-by-line-in-node-js-7775f27c40cc
Effortlessly Reading Files Line-by-Line in Node.js | by Austin Hunt | Hail Trace | Medium
May 6, 2023 - In this article, we’ve covered several approaches to reading files line-by-line in Node.js, including using built-in modules like ‘fs’ and ‘readline’ and third-party libraries like ‘line-reader’. These methods can efficiently process large files without consuming excessive memory.
🌐
Reddit
reddit.com › r/node › how to read a .node file? extremely new to coding and all
r/node on Reddit: How to read a .node file? Extremely new to coding and all
October 15, 2024 -

As stated in the title, there is a .node file in a program I use. When I open it in notepad, it is random symbols, like an encrypted file. I would like to read the file and see what it does. Visual Studio is not able to open it too.

How do I open this file? Which program?

I am extremely new to coding and understand the very basic logics and nomenclature but not much, so please ELI5 it for me. Thanks!

🌐
SitePoint
sitepoint.com › blog › javascript › how to use the file system in node.js
How to use the File System in Node.js — SitePoint
November 13, 2024 - When handling file and directory paths, the node:path module provides cross-platform methods to resolve paths on all operating systems. It offers useful properties and functions like join, resolve, normalize, relative, format, and parse. Node.js offers several functions for reading, writing, updating, and deleting files and directories, including reading files, writing files, creating directories, reading directory contents, and deleting files and directories.