Задать вопрос
  • Почему возникает ошибка You have tried to call .then(), .catch()?

    @Vit632 Автор вопроса
    Обновление-2
    Поиск .then(), .catch() await

    62e2f940cd12c120278283.png



    Обновление-2
    \db\connection.js
    const mysql = require('mysql2');
    const config = require('../config.json');
    const connection = mysql.createConnection({
      host: config.mysql.host,
      user: config.mysql.user,
      password: config.mysql.password,
      database: config.mysql.db,
      charset: 'utf8_general_ci',
      multipleStatements: true
    });
    
    connection.connect();
    
    module.exports = connection;


    Картинка. Поиск "mysql2"
    62e2fc79e3636394753657.png
  • Почему возникает ошибка You have tried to call .then(), .catch()?

    @Vit632 Автор вопроса
    Картинка: поиск .then(), .catch() await

    62e2f992adacf110903413.png
  • Почему возникает ошибка You have tried to call .then(), .catch()?

    @Vit632 Автор вопроса
    …\controllers\main.js

    const db = require('../db');
    const fs = require('fs');
    const path = require('path');
    const config = require('../config.js');
    class Main {
    
      async video(req, res, next) {
        const videoFolder = './static/video'
        let videos = []
    
        fs.readdirSync(videoFolder).forEach((file) => {
          let extension = path.extname(file)
          let filename = path.basename(file, extension)
    
          videos.push({
            file,
            filename: parseInt(filename),
          })
        })
    
        videos = videos.sort((a, b) => {
          return a.filename - b.filename
        })
    
    
    
        return res.render('video', {
          domain: config.express.domain,
          videos,
        })
      }
    
        async panomuseum(req, res) {
        const article = await db.article.getByID(req.params.lang);
        const sub = await db.article.getRoot(req.params.lang);
        const files = await db.files.getByOwnerId(req.params.lang);
    
        const lang = await db.lang.getById(req.params.lang);
    
        return res.render('panomuseum', {
          article,
          sub,
          files,
          lang
        });
      }
    
      async panomuseum2(req, res) {
        const article = await db.article.getByID(req.params.lang);
        const sub = await db.article.getRoot(req.params.lang);
        const files = await db.files.getByOwnerId(req.params.lang);
    
        const lang = await db.lang.getById(req.params.lang);
    
        return res.render('panomuseum2', {
          article,
          sub,
          files,
          lang
        });
      }
    
      async panotheatre(req, res) {
        const article = await db.article.getByID(req.params.lang);
        const sub = await db.article.getRoot(req.params.lang);
        const files = await db.files.getByOwnerId(req.params.lang);
    
        const lang = await db.lang.getById(req.params.lang);
    
        return res.render('panotheatre', {
          article,
          sub,
          files,
          lang
        });
      }
    
      async index(req, res) {
        const article = await db.article.getByID(req.params.lang);
        const sub = await db.article.getRoot(req.params.lang);
        const files = await db.files.getByOwnerId(req.params.lang);
    
    
        const lang = await db.lang.getById(req.params.lang);
        const timeout = await db.settings.getByID("timeout");
        const caption = await db.settings.getByID("caption");
    
    
        return res.render("index", {
          article,
          sub,
          files,
          lang,
          timeout,
          caption,
          domain: req.app.get("domain"),
        });
      }
    
      async menu(req, res) {
        return res.render("menu", {
          domain: req.app.get("domain"),
        });
      }
    
      async slideshow(req, res) {
        const slideshow = await db.files.getSlideshow();
        const timer = await db.settings.getByID("timer");
    
        return res.render("slideshow", {
          slideshow,
          timer,
          domain: req.app.get("domain"),
        });
      }
    
      async slide(req, res) {
        const slideshow = await db.files.getByID(req.params.id);
        const timer = await db.settings.getByID("timer");
    
        return res.render("slideshow", {
          slideshow: [slideshow],
          timer,
          domain: req.app.get("domain"),
        });
      }
    
      async article(req, res) {
        const article = await db.article.getByID(req.params.id);
        const sub = await db.article.getSub(req.params.id);
        const files = await db.files.getByOwnerId(req.params.id);
        const id = req.params.id;
        const lang = await db.lang.getById(req.params.lang);
        const timeout = await db.settings.getByID("timeout");
        const caption = await db.settings.getByID("caption");
    
        return res.render("index", {
          id,
          article,
          sub,
          files,
          lang,
          timeout,
          caption,
          domain: req.app.get("domain"),
        });
      }
    
      
      async lang(req, res) {
        const langs = await db.lang.getAll();
    
        let activeCount = 0;
    
        for (let lang of langs) {
          if (lang.value == 1) {
            activeCount++;
          }
        }
    
        if (activeCount == 0) {
          return res.redirect("/0");
        } else if (activeCount == 1) {
          for (let lang of langs) {
            if (lang.value == 1) {
              return res.redirect("/" + lang.id);
            }
          }
        }
    
        const timeout = await db.settings.getByID("timeout");
    
        return res.render("lang", {
          langs,
          timeout,
        });
      }
    
      async openSlide(req, res) {
        console.log("openSlide");
        let files = await db.files.getSyncSmartHome();
    
        parentIO.sockets.in("client").emit("goToUrl", {
          message: "/slide/" + files[parseInt(req.params.id)].id,
        });
    
        return res.json({
          success: true,
        });
      }
    
      async openSlideshow(req, res) {
        console.log("open slideshow");
    
        parentIO.sockets.in("client").emit("goToUrl", {
          message: "/slideshow",
        });
    
        return res.json({
          success: true,
        });
      }
    }
    
    module.exports = new Main();


  • Почему возникает ошибка You have tried to call .then(), .catch()?

    @Vit632 Автор вопроса
    Какой код выложить?
    Это?
    at Query.then (e:\Test\Pro01\node_modules\mysql2\lib\commands\query.js:41:11)
    at MySQLStore.query (e:\Test\Pro01\node_modules\express-mysql-session\index.js:392:12)
    at MySQLStore. (e:\Test\Pro01\node_modules\express-mysql-session\index.js:110:9)
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)

    -----
    Я только разбираюсь с NODE JS.
    Прошу извинить за некорректность...

    Обновление-1
    Эли это замечание по всему проекту?

    Обновление-2
    См. вопрос Обновление-1
    Добавил код app.js