Housekeeping, tag and build

This commit is contained in:
Angelos Chalaris
2017-12-16 13:56:55 +02:00
parent a3110916d1
commit 6eb818309e
7 changed files with 92 additions and 23 deletions

View File

@ -0,0 +1,19 @@
### Read file as array of lines
Use `readFileSync` function in `fs` node package to create a `Buffer` from a file.
convert buffer to string using `toString(encoding)` function.
creating an array from contents of file by `split`ing file content line by line(each `\n`).
```js
const fs = require('fs');
const readFileToArray = filename => fs.readFileSync(filename).toString('UTF8').split('\n');
/*
contents of test.txt :
line1
line2
line3
___________________________
let arr = readFileToArray('test.txt')
console.log(arr) // -> ['line1', 'line2', 'line3']
*/
```