我的module.exports由于某些原因不起作用?

时间:2016-02-16 23:01:34

标签: javascript node.js module

我正在尝试将变量从app.js导出到export.js文件,但由于某些原因它无法正常工作。它曾经工作,但我不能再获得jsondata变量的值。请帮帮我!

// route.js

var express = require('express');
var js_app = require('./app.js');
//console.log(js_app);
var data = js_app;
//console.log(data);
module.exports = function(){                
    var app = express();
    console.log("Log inforLog infor..");
    app.set('views', './static/');
    app.set('view engine', 'jade');
    app.get('/', function(req, res) {
      res.render('index', data);
    });            
    return app;

};

// app.js

var request = require('request');
var setting = require('./config/configuration.js');

request({url: setting[0]},function(error, response, body){
    if(!error && response.statusCode == 200){
            console.log(JSON.parse(response.body));
    } 
    });


request({url: setting[0]+'/'+"dr_sc_values_from_31415927/_design/id_view/_view/viewID?limit=10"},function(error, response, body){
    console.log(response.statusCode);
    if(!error && response.statusCode == 200){
     var response_view = JSON.stringify(eval("(" + response.body + ")"));
     var jsondata = JSON.parse(response_view).rows;
      console.log(jsondata);
      module.exports = jsondata; // this is one, I want to exprt
    } 
    });

0 个答案:

没有答案