如何将数据从node.js获取到公用文件夹中的静态javascript文件

如何将数据从node.js获取到公用文件夹中的静态javascript文件,javascript,node.js,express,mongoose,Javascript,Node.js,Express,Mongoose,我是node.js的新手。我必须将数据从节点发送到静态javascript文件。我已经收集了一些问题,我想将这些问题发送到此javascript文件: var model = { questionSummary:[], noOfQuestions:0, init: function () { // if (!localStorage.getItem("questions")) { // localStorage.setItem("q

我是node.js的新手。我必须将数据从节点发送到静态javascript文件。我已经收集了一些问题,我想将这些问题发送到此javascript文件:

var model = {
    questionSummary:[],
    noOfQuestions:0,
    init: function () {
        // if (!localStorage.getItem("questions")) {
        //     localStorage.setItem("questions", JSON.stringify([]));
        // }
        if(!localStorage.getItem("noOfQuestions")){
            localStorage.setItem("noOfQuestions",JSON.stringify(0));
        }
        else{   
         model.noOfQuestions = localStorage.getItem("noOfQuestions");
        }

        if (!localStorage.getItem("author")) { //todo
            localStorage.setItem("author","Anonymus");
        }
        if (!localStorage.getItem("currentQuestionId")) {
            localStorage.setItem("currentQuestionId", '1');
        }
        for(var index=1;index<=this.noOfQuestions;index++)
            this.questionSummary.push(JSON.parse(localStorage.getItem("question"+index)));
    },
    getAllQuestions: function () { //todo
        return this.questionSummary;
    },
    increment: function(questionBlockId) {
        this.questionSummary[questionBlockId].views++;
    },
    setter: function(property,value){
        localStorage.setItem(property, JSON.stringify(value));
    }
};
var模型={
问题摘要:[],
无问题:0,
init:函数(){
//如果(!localStorage.getItem(“问题”)){
//setItem(“问题”,JSON.stringify([]);
// }
如果(!localStorage.getItem(“noOfQuestions”)){
setItem(“noOfQuestions”,JSON.stringify(0));
}
否则{
model.noOfQuestions=localStorage.getItem(“noOfQuestions”);
}
如果(!localStorage.getItem(“author”){//todo
setItem(“作者”、“匿名”);
}
如果(!localStorage.getItem(“currentQuestionId”)){
setItem(“currentQuestionId”,“1”);
}

对于(var index=1;indexI我不确定您到底需要知道什么,但让我试试看:您想将node.js服务器上的数据输入到您在浏览器中运行的代码中吗?在这种情况下,您需要使用一个路由来为服务器上的数据提供服务,并使用ajax调用来获取数据。如果您想将数据注入到文件中,您就可以这样做关于读取/写入文件以修改它。@Stian我想从node.js服务器获取数据到我正在浏览器中运行的代码中,以便能够呈现这些数据。虽然我可以在html中获取这些数据,但我需要在javascript文件中获取这些数据。我对Ajax知之甚少,如果您能提供参考,那将是一个非常好的选择帮助。你到底想做什么清楚你的问题似乎模棱两可。你不能理解你在客户端使用任何框架吗?大多数框架都有简单的抽象来为你做到这一点。如果没有,这里是对本机js方法的参考:但如果你不熟悉,我会看看jQuery、Angular等框架。