node.js read text file line by line
const fs = require('fs');
fs.readFile('file.txt', function(err, data) {
if(err) throw err;
const arr = data.toString().replace(/\r\n/g,'\n').split('\n');
for(let i of arr) {
console.log(i);
}
});
const readline = require('readline');
const readInterface = readline.createInterface({
input: fs.createReadStream('name.txt'),
output: process.stdout,
console: false
});
for await (const line of readInterface) {
console.log(line);
}
//or
readInterface.on('line', function(line) {
console.log(line);
});
Also in JavaScript:
- generate random number in java
- set ibm cloud node environment variables
- how to rename zip file nodejs
- js self driving car
- check if file exists javascript
- jquery format date
- how to make a array in javascript
- slickcdn
- shadow class angular
- localstorage javascript
- bearer token header
- react propthpes or
- single node elasticsearch with enable security basic in docker
- How to write on a web page javascript
- how to count specific letters in string js
- jquery delete grand parent of clicked element
- criar objeto javascript
- javascript get first character of string
- promise all in promise all
- detecting change in animated value react native
- jquery add element array
- Iterate Through an Array with a For Loop
- toggle element javascript
- ajax file upload jquery