There are multiple ways to read a file line by line with Node.js. read In ogni caso, se desideri elaborare il file una riga alla volta, puoi anche provare qualcosa del genere: See notes for 'rs' about using this with caution. 4: rs+. Callback function is provided as an argument to readFile function. Reading 0. node read file line. Open file for reading in synchronous mode. This question needs some serious editing and cleanup. var readline = require('readline'); Using the Node.js readline module . var fs = require('fs'); search.nodejs.org JavaScript. XML Files If you want to read a file into an array, there’s no straightforward way to do it. It can be achieved by returning false from the callback function: linebyline is another open-source library that can be used to read a file line by line in Node.js. Let us add it your project: This package simply streams the native readline module internally, reads and buffers new lines emitting a line event for each line: 3) Produce a header array. Reading files with Node.js. Each line read is pushed into the lines array. It is not the native module, so you need to install it using npm (Node Package Manager) using the command: npm install line-reader --save. 2) Convert the data to String and divide it into an array. Reading CSV files. Thank you! The fs.readFile () and fs.readFileSync () methods are used for the reading files. How to Use JSON files in Node.js