heroku上的调查网站Node.js data collection anamoly
我在一个包含表单的网站上工作。 我的要求是收集每个用户的所有表单数据 这是一个资金紧张的学术项目,因此我使用heroku免费服务器空间 我选择了node.js express framework。 创建了一个简单的表单,在提交时,它会向文件中写入一个json。下面是代码heroku上的调查网站Node.js data collection anamoly,node.js,mongodb,express,heroku,web-deployment,Node.js,Mongodb,Express,Heroku,Web Deployment,我在一个包含表单的网站上工作。 我的要求是收集每个用户的所有表单数据 这是一个资金紧张的学术项目,因此我使用heroku免费服务器空间 我选择了node.js express framework。 创建了一个简单的表单,在提交时,它会向文件中写入一个json。下面是代码 //require the express nodejs module var express = require('express'), //set an instance of exress app = ex
//require the express nodejs module
var express = require('express'),
//set an instance of exress
app = express(),
//require the body-parser nodejs module
bodyParser = require('body-parser'),
//require the path nodejs module
path = require("path");
var fs = require("fs");
//support parsing of application/json type post data
app.use(bodyParser.json());
//support parsing of application/x-www-form-urlencoded post data
app.use(bodyParser.urlencoded({ extended: true }));
//tell express that www is the root of our public web folder
app.use(express.static(path.join(__dirname, 'www')));
//tell express what to do when the /form route is requested
app.post('/form',function(req, res){
res.setHeader('Content-Type', 'application/json');
//mimic a slow network connection
setTimeout(function(){
res.send(JSON.stringify({
firstName: req.body.firstName || null,
lastName: req.body.lastName || null
}));
var fileContent = JSON.stringify(req.body);
fs.writeFile("./sample.txt", fileContent, (err) => {
if (err) {
console.error(err);
return;
};
console.log("File has been created");
});
}, 1000)
//debugging output for the terminal
console.log('you posted: First Name: ' + req.body.firstName + ', Last Name: ' + req.body.lastName);
});
app.set('port', (process.env.PORT || 5000));
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'));
});
当我在localhost上运行它时,它工作得非常好,创建了一个文件
但是当我在heroku上部署它,运行,然后克隆repo时,没有文件
虽然这是低级问题,但在更高的级别上,我只需要一个带有动态表单和服务器空间的网页来收集数据。我不想在这项活动上花费太多时间,因为我的实际工作是基于数据的。我很确定github页面不起作用。我们集成了谷歌表单,它可以工作,但网页不是动态的。因此,我的具体问题从高级问题到低级问题依次为: