NodeJS read the contents of the file and format the question for advice?

I have N txt files with each row of data and how many fields each line has. Can NodeJS read this file and get json formatted data?

ask for advice on how to use api to implement, or give a small demo thank you, online urgent wait

Jan.18,2022

this kind of random search is a lot of information. What is there to ask for advice?
introduce fs into fs . Json can directly use the string read JSON.parse . If it is not a standard JSON, it is nothing more than a string cutting function split or regular cutting and assembling

.
const fs = require('fs');

const path = 'd:/node/demo.txt';
const str = fs.readFileSync(path).toString();

console.log(str);
console.log(JSON.parse(str));

1. Node can read the contents of a file. You can refer to Node official document-File Operation
2. Formatting the file content as JSON, depends on the format of your data, how the key:value is divided, and how each key is divided. You can use regular matching to get


text-2-json

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7ba838-8d14.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7ba838-8d14.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?