使用Node.JS,如何将JSON文件读入(服务器)内存?

JavaScript

Tony凯

2020-03-12

背景

我正在对Node.js进行一些试验,想从文本文件或.js文件(更好的??)中读取JSON对象到内存中,以便我可以从代码中快速访问该对象。我意识到那里有像Mongo,Alfred等的东西,但是那不是我现在所需要的。

如何使用JavaScript / Node从文本或js文件中读取JSON对象并将其读入服务器内存中?

第896篇《使用Node.JS,如何将JSON文件读入(服务器)内存?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
乐米亚 2020.03.12

So many answers, and no one ever made a benchmark to compare sync vs async vs require. I described the difference in use cases of reading json in memory via require, readFileSync and readFile here.

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android