Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
heroku上的调查网站Node.js data collection anamoly_Node.js_Mongodb_Express_Heroku_Web Deployment - Fatal编程技术网

heroku上的调查网站Node.js data collection anamoly

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

我在一个包含表单的网站上工作。 我的要求是收集每个用户的所有表单数据

这是一个资金紧张的学术项目,因此我使用heroku免费服务器空间

我选择了node.js express framework。 创建了一个简单的表单,在提交时,它会向文件中写入一个json。下面是代码

//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页面不起作用。我们集成了谷歌表单,它可以工作,但网页不是动态的。因此,我的具体问题从高级问题到低级问题依次为:


  • 是否有创建网页和收集数据的框架?heroku是一个灵活的选择吗?数据生成量不会很大,我们希望出于我的目的,表单提交是唯一的要求。我在使用,所以我放弃了这条路。但问题仍然存在,为什么不在heroku服务器上创建文件。。