Skip to content

Instantly share code, notes, and snippets.

@emmaexe
Created November 23, 2021 17:40
Show Gist options
  • Save emmaexe/e97dbe98d4b2a51d72a691f416556d2c to your computer and use it in GitHub Desktop.
Save emmaexe/e97dbe98d4b2a51d72a691f416556d2c to your computer and use it in GitHub Desktop.
Converter for transforming every line of a TXT file into its seperate entry inside a JSON file
const config = {
"inputfile":"list.txt",
"outputfile":"list.json"
}
const fs = require('fs')
const readline = require('readline');
(async () => {
console.log('Started.')
const fileStream = fs.createReadStream(config.inputfile);
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
const out = [];
rl.on('line', async (line) => {
out.push(line)
})
rl.on('close', () => {
fs.writeFile(config.outputfile, JSON.stringify(out), (err) => {
if (err) return console.error(err)
else console.log('Completed.')
})
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment