如何从读取的文件中打印变量?

时间:2018-10-27 09:44:37

标签: node.js function file

我有一个文件名为.js。这是文件的内容

var country = "India";
var createdOn = "1512086400000";
var schoolType = "Listing+App";

 Promo1 = function sample(schoolid,schoolCollecName,PromocollecName){
schoolCollecName.find({$and:[{"_id":schoolid},{"createdOn":{$lte:createdOn}},{"country":country},{"schoolType":"Listing+App"}]},function(err,school){
        if(err){
            return console.log(err);
        }
        else if(school.length>0){
PromocollecName.find({$and:[{"packageName":school[0].package},{"country":country}]},function(err,promoCards){
    if(err){
        return console.log(err);
    }
    else if(promoCards.length>=0){
        res.status(200).json({status:true,details:promoCards});
    }
});     
}
else if(school.length==0){
    res.status(200).json({status:true,details:[]});     
    }
});
}

此文件位于远程位置,假设它位于AWS S3中。我只写了几行内容来读取function.js文件并从该文件中调用一个函数。这是它的代码

functionNAme = "Promo1";
request.get("https://s3.amazonaws.com/function.js", function (error,body) {
if(error){
    return console.log(error);
}   
else{
console.log("callback",body);  // file is printing in logs
console.log("function",body.Promo1);  //getting this as undefined
body.functionNAme(req.params.schoolid,schoolModel,promoCardsModel);//Here not able to call that function
}
});

至少我不能从该文件中打印变量。帮我解决这个问题。

0 个答案:

没有答案