服务器上传
以下脚本用于将文件从服务器文件系统上载到服务器。主要用于配置文件和文件监视器。
//https://forums.meteor.com/t/read-file-from-the-public-folder/4910/5
// Asynchronous Method.
Meteor.startup(function () {
console.log('starting up');
var fs = Npm.require('fs');
// file originally saved as public/data/taxa.csv
fs.readFile(process.cwd() + '/../web.browser/app/data/taxa.csv', 'utf8', function (err, data) {
if (err) {
console.log('Error: ' + err);
return;
}
data = JSON.parse(data);
console.log(data);
});
});
// Synchronous Method.
Meteor.startup(function () {
var fs = Npm.require('fs');
// file originally saved as public/data/taxa.csv
var data = fs.readFileSync(process.cwd() + '/../web.browser/app/data/taxa.csv', 'utf8');
if (Icd10.find().count() === 0) {
Icd10.insert({
date: new Date(),
data: JSON.parse(data)
});
}
});
Meteor.methods({
parseCsvFile:function (){
console.log('parseCsvFile');
var fs = Npm.require('fs');
// file originally saved as public/data/taxa.csv
var data = fs.readFileSync(process.cwd() + '/../web.browser/app/data/taxa.csv', 'utf8');
console.log('data', data);
}
});