Javascript 正在对此函数调用进行未定义

Javascript 正在对此函数调用进行未定义,javascript,Javascript,我认为写数据库需要时间这一事实使得这个函数没有定义。我说得对吗?如果是这样,程序员如何避免在数据库调用的回调中出现一百万个嵌套函数 function createStripeCustomer(email) { stripe.customers.create({ email: email }, function (err, customer) {

我认为写数据库需要时间这一事实使得这个函数没有定义。我说得对吗?如果是这样,程序员如何避免在数据库调用的回调中出现一百万个嵌套函数

function createStripeCustomer(email) {
            stripe.customers.create({
                    email: email
                },
                function (err, customer) {
                    if (err) {
                        console.log('The stripe error is ', err);
                    }
                    console.log('The created customer id is ', customer.id); // This works

                    return customer.id;   // we know customer.id works because it shows up in console 
                }
            );
}
出于某种原因,这会给出未定义的:

var getCustomerId = createStripeCustomer(req.body.email);
console.log ('This should say the id but it says undefined: ', getCustomerId);

谢谢你!我应该把它放在哪里呢?那么在我的例子中呢?在createStripeCustomer(req.body.email)之后?同样,我对你作为一个堆栈溢出名人印象深刻:)谢谢你的天才!要使用
.then()
,必须使函数返回一个承诺,您正在使用的API可能已经返回,也可能没有返回。如果没有,请参见