讓我們創(chuàng)建一個 private 文件夾并在這個文件內(nèi)創(chuàng)建 my-json.json 文件。我們將從命令提示符窗口來創(chuàng)建目錄,但您可以手動創(chuàng)建它。
C:\Users\Administrator\Desktop\meteorApp>mkdir private
C:\Users\Administrator\Desktop\meteorApp\private>touch my-json.json
為了能夠從文件中讀取數(shù)據(jù),使用Assets.getText方法。要記住重要的是,這只能在服務(wù)器端來完成。由于我們使用JSON,需要分析它。
if (Meteor.isServer) {
var myFile = JSON.parse(Assets.getText('my-json.json'));
console.log(myFile.data.text)
}

我們將在 private 文件夾內(nèi)創(chuàng)建此文件。此文件將包含二進制數(shù)據(jù) "myBinary": {"$binary": "c3VyZS4="}
C:\Users\Administrator\Desktop\meteorApp\private>touch my-ejson.ejson
if (Meteor.isServer) {
var myFile = Assets.getBinary('my-ejson.ejson');
console.log(EJSON.stringify(myFile));
}

