我正在尝试使用cronjob重复更新文件。最终,这将变得更加复杂,但现在我想弄清楚我目前的问题。我知道下面的代码有点过于复杂,因为我在尝试解决问题时保留了基本结构。这是服务器文件:
// server.js
var express = require('express');
var port = process.env.PORT || 8080;
var http = require('http');
var fs = require("fs");
var curtainup = require('./diagnoseleak.js');
var url = require("url" );
var app = express();
// launch ======================================================================
app.listen(port);
//run the CronJob
var CronJob = require('cron').CronJob;
new CronJob('0 * * * * *', function() {
console.log("running");
var date = new Date();
console.log("Ran at: "+date.getHours()+":"+date.getMinutes());
curtainup.doitnow();
} , null, true, 'America/New_York');
以下是名为diagnoseleak.js
的文件:
var fs = require("fs");
var mostRecentLocation = "./config/pullfiles/mostRecent55.txt";
module.exports = {
doitnow: function(){
var writethefile = function(){
fs.writeFileSync(mostRecentLocation, "A file called mostRecent55 should be create with this text", { flag: 'w' });
console.log("This should write to the console");
}
writethefile();
}
}
从包含服务器文件的目录中,我将以下内容键入cmd:
git add .
git commit -m "adding files"
git push heroku master
heroku run bash
然后进入bash窗口我输入:
cd config/pullfiles
ls -l
AND ...不会出现名为mostRecent55.txt
的文件。我在找错了地方吗?最终我希望能够更新文件,但我有一种感觉,我要么找错了这个mostRecet55.txt
文件的位置,要么就是错误地编写文件。
答案 0 :(得分:1)
heroku
不允许您将文件写入存储应用的文件系统。您将需要使用某种插件,数据库或某种外部服务。唯一的例外似乎是/tmp
,它只是临时存储