Tuesday, 2 May 2017

how to return value from a function nodejs

this is the function of nodejs

class Login{ //...

    static login(login, password,token){
        let info="";

        let options = {
            method: 'PUT',
            url: 'http://example.com',
            headers: {
                authorization: "Basic " + token,
                'content-type': 'application/xml'
            }
        }

            request(options, function (error, response, body) {
                if (error){
                    console.log(new Error(error));
                    throw new Error(error);

                }
                else{

                    info="success";

                }

            });

        return info;

    };  
}

and when I require this function, I want to get the value of the info

let value=Login.login(login, password,token);

but I can't get the value of info, someone can help me? thank you very much !



via windleaf5188

No comments:

Post a Comment