您可以导出
friends
来自朋友的数组。js模块如下:
// array of objects
const friends = [
{
routeName: "ahmed",
name:"Ahmed",
photourl:"https://media.licdn.com/mpr/mpr/shrinknp_400_400/p/6/005/064/1bd/3435aa3.jpg",
questions:[
5,
1,
4,
4,
5,
1,
2,
5,
4,
1
]
}
];
module.exports = function(app){
//retreiving stored objects with person's data
app.post("/survey", function(req, res){
var incomingPerson = req.body;
incomingPerson.routeName = incomingPerson.name.replace(/\s+/g, "").toLowerCase();
console.log(incomingPerson);
// friends.push(person);
});
return friends;
};
module.exports.friends = friends;
然后,任何你想访问singleton的地方
朋友
数组,可以执行以下操作:
const friends = require('./friends.js').friends;