Node.js Return语句不起作用,但console.log()起作用

我能够从数据库中获取数据,但返回该数据作为对所发出请求的响应是一个问题。

 `    // create employees and save into the databse
async save(resp) {

    this.bcrypt.hash(this.user.password,10).then( (hash)=>{

        let params = [this.user.firstName,this.user.lastName,this.user.email,this.user.password,this.user.gender,this.user.jobRole,this.user.department,this.user.address];

       this.client.query( 
        'INSERT into employees (firstName,lastName,email,password,gender,jobRole,department,address) VALUES($1,$2,$3,$4,$5,$6,$7,$8) RETURNING userId',params)

        .then ( (result) => {

            try {
                let userFetched = result.rows[0].userid;
                this.client.query("SELECT * FROM employees WHERE userid = $1",[userFetched])
                    .then( (res)=>{

                        console.log(res.rows[0]);
                        return res.rows[0];

                    })

                    .catch( (err)=>{
                        console.log(err);
                    })


            } catch (error) {
                return {
                    error: "Employee could not be created correctly."
                }
            }

        })

        .catch( (err)=>{
            return {
                error: "Something went wrong. Try again later."
            }
        })


    })

}`

如果我对获取的数据进行控制台,那是可行的,但是返回它是问题所在。我不断收到错误消息。请帮忙。

kimwang062283 回答:Node.js Return语句不起作用,但console.log()起作用

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3129959.html

大家都在问