【发布时间】:2021-11-11 13:46:57
【问题描述】:
我对这个领域真的很陌生,刚开始我的第一个项目,我不想使用复杂的数据库,我只想将一个简单的二维数组(表)存储到文件中,以便我以后可以检索它,我确实看过 fs.writeFile 但它似乎不接受这种格式的数组...
我对这个领域真的很陌生,所以如果有任何其他存储数据的方式,或者如果这是一种非常糟糕的存储数据方式,那么请建议我该怎么做
var myArray = [
["bob","john","jack"],
[62,31,11],
["employed","unemployed","uneligible"],
["engineer","doctor","student"],
["21/09/2021","28/11/2021","16/12/2021"]]
如何将其保存到文件(任何文件)以供以后使用
// something like this
writeToFile( "./info.db" , myArray )
// inside the file info.db
[["bob","john","jack"],[62,31,11],["employed","unemployed","uneligible"],["engineer","doctor","student"],["21/09/2021","28/11/2021","16/12/2021"]]
并且为了将该数组作为数组返回,我确实尝试使用带有 utf8 编码的 readFileSync,但是当我尝试读取数据时,我将数据作为缓冲区返回[0],我得到了第一个字符字符串“[”
【问题讨论】:
标签: javascript node.js database store fs