Answer the question
In order to leave comments, you need to log in
MVC node server refactoring?
I made a server, but it consists of one file and I was told to make it according to the MVC architecture, I don’t know if I understood correctly what MVC is, but I’m trying to do the following thing. Where it says that the problem is here, I want the variable g to be a separate function, which I will of course move to another module, and that this function return the result of reply. If something is not clear, write, I will correct it, I really need help. But maybe I misunderstood the idea of MVC and it does not need to be separated somehow, then I will be glad to hear how it should be. In essence, the question in general is, how do I correctly refactor this code, guided by the MVC architecture?
app.post('/get-staff',function(req,res) {
prom=new Promise(function(resolve,reject) {
//проблема здесь
let g=client.hgetall('user',function(err,reply) {
return reply;
});
resolve(g);
//
}).then(function(result) {
return new Promise(function(resolve,reject) {
client.get('id',function(err,reply) {
console.log(reply);
let arr=Array.of();
for(let i=0;i<=reply;i++)
{
arr.push(JSON.parse(result[i]));
}
resolve(arr);
})
}).then(function(result) {
console.log(result);
res.send(result);
return ;
});
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question