Apply for Zend Framework Certification Training

NodeJs




< Create registration api using nodejs mongodb express Last >



Step -1) create a function in userscontroller
 
exports.login = async (request,response)=>{
        var email = request.body.email;
        var password = request.body.password;
        logindata = {email:email}
        if(email != '' && password != ''){
            var userdata = await users.findOne(logindata)
            if(userdata == null){
                response.send(JSON.stringify({'status': 200,'error':'',
                      'message':'please enter your correct credentials'}))
            }else if(userdata.password === password){
                response.send(JSON.stringify({'status': 200,'error':'',
                      'message':userdata}))
            }else{
                response.send(JSON.stringify({'status': 200,'error':'',
                      'message':'please enter your correct credentials'}))
            }
           
        }else{
            response.send(JSON.stringify({'status': 200,'error':'',
                      'message':'please enter your credentials'}))
        }
}
 
Step -2) Add a line of code in userroutes.js
 
router.post('/login',usercontroller.login)

< Create registration api using nodejs mongodb express Last >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top