本文介绍了Nodejs 表达并承诺不会做我期望的事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
限时送ChatGPT账号..
我正在尝试使用 NodeJS 构建登录 API,但我的代码没有按照我的预期运行.我对 js、promise 和所有内容都很陌生,因此请尽可能简化任何答案.
I am trying to build a login API using NodeJS, but my code is not doing what I expect it to. I am very new to js, promises and all so please simplify any answer if possible.
从我在代码输出中看到的,第一个 promise 部分不会等到函数 findUsers(...)
完成.
From what I can see in the output of my code, the first promise part does not wait until the function findUsers(...)
is finished.
我有一个路由文件,我想在其中按顺序运行一些函数:
I have a routes file where I want to run a few functions sequentially:
- 查找数据库中是否存在用户
- if(1 is true) 对输入的密码进行哈希和加盐
- ...等
路由文件现在包含:
findUser
函数包含池化和查询,并位于模型文件中:
And the findUser
function contains pooling and a query and is in a models file: