<small id='aQ31H'></small><noframes id='aQ31H'>

      <i id='aQ31H'><tr id='aQ31H'><dt id='aQ31H'><q id='aQ31H'><span id='aQ31H'><b id='aQ31H'><form id='aQ31H'><ins id='aQ31H'></ins><ul id='aQ31H'></ul><sub id='aQ31H'></sub></form><legend id='aQ31H'></legend><bdo id='aQ31H'><pre id='aQ31H'><center id='aQ31H'></center></pre></bdo></b><th id='aQ31H'></th></span></q></dt></tr></i><div id='aQ31H'><tfoot id='aQ31H'></tfoot><dl id='aQ31H'><fieldset id='aQ31H'></fieldset></dl></div>
      <tfoot id='aQ31H'></tfoot>

        <bdo id='aQ31H'></bdo><ul id='aQ31H'></ul>
      1. <legend id='aQ31H'><style id='aQ31H'><dir id='aQ31H'><q id='aQ31H'></q></dir></style></legend>

        Nodejs 表达并承诺不会做我期望的事情

        Nodejs express and promises not doing what I expect(Nodejs 表达并承诺不会做我期望的事情)
          <tbody id='uj0iG'></tbody>

        <small id='uj0iG'></small><noframes id='uj0iG'>

        <legend id='uj0iG'><style id='uj0iG'><dir id='uj0iG'><q id='uj0iG'></q></dir></style></legend>

          <i id='uj0iG'><tr id='uj0iG'><dt id='uj0iG'><q id='uj0iG'><span id='uj0iG'><b id='uj0iG'><form id='uj0iG'><ins id='uj0iG'></ins><ul id='uj0iG'></ul><sub id='uj0iG'></sub></form><legend id='uj0iG'></legend><bdo id='uj0iG'><pre id='uj0iG'><center id='uj0iG'></center></pre></bdo></b><th id='uj0iG'></th></span></q></dt></tr></i><div id='uj0iG'><tfoot id='uj0iG'></tfoot><dl id='uj0iG'><fieldset id='uj0iG'></fieldset></dl></div>

          • <bdo id='uj0iG'></bdo><ul id='uj0iG'></ul>

                <tfoot id='uj0iG'></tfoot>

                • 本文介绍了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:

                  1. 查找数据库中是否存在用户
                  2. if(1 is true) 对输入的密码进行哈希和加盐
                  3. ...等

                  路由文件现在包含:

                  var loginM = require('../models/login');
                  var loginC = require('../controllers/login');
                  var Promise = require('promise');
                  
                  module.exports = function(app) {
                  
                      app.post('/login/', function(req, res, next) {
                  
                          var promise = new Promise(function (resolve, reject) {
                              var rows = loginM.findUser(req.body, res);
                  
                              if (rows.length > 0) {
                                  console.log("Success");
                                  resolve(rows);
                              } else {
                                  console.log("Failed");
                                  reject(reason);
                              }
                          });
                  
                          promise.then(function(data) {
                              return new Promise(function (resolve, reject) {
                                  loginC.doSomething(data);
                  
                                  if (success) {
                                      console.log("Success 2");
                                      resolve(data);
                                  } else {
                                      console.log("Failed 2");
                                      reject(reason);
                                  }
                              });
                          }, function (reason) {
                              console.log("error handler second");
                          });
                      });
                  }
                  

                  findUser 函数包含池化和查询,并位于模型文件中:

                  And the findUser function contains pooling and a query and is in a models file:

                  var connection = require('../dbConnection');
                  var loginC = require('../controllers/login');
                  
                  function Login() {
                      var me = this;
                      var pool = connection.getPool();
                  
                      me.findUser = function(params, res) {
                          var username = params.username;
                  
                          pool.getConnection(function (err, connection) {
                              console.log("Connection ");
                  
                              if (err) {
                                  console.log("ERROR 1 ");
                                  res.send({"code": 100, "status": "Error in connection database"});
                                  return;
                              }
                  
                              connection.query('select Id, Name, Password from Users ' +
                                  'where Users.Name = ?', [username], function (err, rows) {
                                  connection.release();
                                  if (!err) {
                                      return rows;
                                  } else {
                                      return false;
                                  }
                              });
                  
                              //connection.on('error', function (err) {
                              //    res.send({"code": 100, "status": "Error in connection database"});
                              //    return;
                              /
                                  
                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
                  MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
                  Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
                  How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
                  Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
                  Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)
                • <legend id='Qzf0Z'><style id='Qzf0Z'><dir id='Qzf0Z'><q id='Qzf0Z'></q></dir></style></legend>

                  • <tfoot id='Qzf0Z'></tfoot>
                    <i id='Qzf0Z'><tr id='Qzf0Z'><dt id='Qzf0Z'><q id='Qzf0Z'><span id='Qzf0Z'><b id='Qzf0Z'><form id='Qzf0Z'><ins id='Qzf0Z'></ins><ul id='Qzf0Z'></ul><sub id='Qzf0Z'></sub></form><legend id='Qzf0Z'></legend><bdo id='Qzf0Z'><pre id='Qzf0Z'><center id='Qzf0Z'></center></pre></bdo></b><th id='Qzf0Z'></th></span></q></dt></tr></i><div id='Qzf0Z'><tfoot id='Qzf0Z'></tfoot><dl id='Qzf0Z'><fieldset id='Qzf0Z'></fieldset></dl></div>

                    <small id='Qzf0Z'></small><noframes id='Qzf0Z'>

                        <tbody id='Qzf0Z'></tbody>

                          • <bdo id='Qzf0Z'></bdo><ul id='Qzf0Z'></ul>