简体   繁体   English

如何从node.js中的mysql获取数据

[英]how to get data from mysql in node.js

I don't know what is the problem.. 我不知道是什么问题。

This code has 'SyntaxError: Unexpected identifier' err in line 14. 该代码在第14行中显示“ SyntaxError:意外的标识符”错误。

What is the problem between query and database pool? 查询和数据库池之间有什么问题?

const express = require('express');
const router = express.Router();
const request=require('async');
const db = require('../../module/pool.js');

router.get('/:user_id', (req, res) => {
    try {
        if(!(req.params.user_id)){
             res.status(403).send({
               message : "no user_id input"
            });
         } else {
            let query = 'select A.store_name, A.store_img, count(B.store_idx) as review_cnt from board.store A Left Join board.review B On A.store_idx is B.store_idx where store_idx is (select A.store_idx from bookmark where user_id = ?)';
            let bookmarks = await db.queryParam_Arr(query, [req.params.user_id]);   

        if (!bookmarks) {                                               
            res.status(500).send({
                msg : "No Bookmarks"
            });
        } else {
            res.status(200).send({
                msg : "Successfully get list",
                list :  bookmarks
             });
            }
         }
    } catch (err) {
        console.log(err);
        res.status(500).sen ({
            msg : "syntax err"
        });
    }    

});

module.exports = router;

You are using await (line 14) but the function is not async . 您正在使用await (第14行),但是该函数不是async

just updated your route definition in this way 刚刚以这种方式更新了路线定义

router.get('/:user_id', async(req, res) => {
   // your code
});

and it should work properly. 它应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Node.js从MySQL获取数据并将其输出为HTML - Get data from MySQL and output it to HTML using Node.js 如何使用node.js从MySQL获取可读的字符串? - How to get readable string from mysql with node.js? 如何在浏览器中的 Node.js 中显示 MySQL 数据库中的数据 - How to display Data from MySQL database in Node.js in browser 如何在Node.js应用程序中将数据从Redis保存到MySQL - How to persist data from Redis to MySQL in a Node.js app Node.js在MySQL上获取数据并对最新数据进行排序 - Node.js Get data on MySQL and sorting newest data 我们如何使用node.js从angular 7应用程序中的mysql数据库中获取数据并将其显示在angular组件html页面上 - How can we get data from mysql database in angular 7 application by using node.js and display it on angular component html page 在node.js(express)中获取MySQL数据并使用EJS进行打印 - Get MySQL data in node.js (express) and print using EJS 获取 VARCHAR 中日期之间的数据(Mysql 和 node.js) - Get data between dates in VARCHAR (Mysql and node.js) 使用Node.js从MySQL获取数据并将其显示在索引页面上 - Get data from MySQL using Node.js and display it on index page 在使用变量之前,Node.js尝试使用async / await从mysql select中获取数据 - Node.js trying to use async/await to get data from a mysql select before using the variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM