错误:rout.get()需要一个回调函数,但得到了[对象未定义] - 搜索express

发布于 2025-02-07 13:08:57 字数 878 浏览 0 评论 0原文

我正在尝试使用查询(express nodejs)来修复搜索功能,但是我收到了此错误消息...有什么想法我缺少什么?

谢谢!

路线:

const SearchController = require("../controllers/search");
route.get("/search/limit", SearchController.searchLimit);

搜索功能:

const Product = require("../models/Product");

const searchLimit = async (req, res) => {
  try {
    const { keywords } = req.query;
    keywords = keywords.toLowerCase();
    Product.findAll(
      { where: { keywords: { [Op.like]: "%" + term + "%" } } },
      { limit: 5 }
    )
      .then((output) => res.send("search result", { output }))
      .catch((error) => console.log(error));
  } catch (err) {
    coneole.log(err);
    return err;
  }
};

module.export = { searchLimit };

错误消息:

Error: Route.get() requires a callback function but got a [object Undefined]

I'm trying to fix a search functionality with query (express nodeJS) but I get this error message... Any ideas what I'm missing?

Thanks!

the route:

const SearchController = require("../controllers/search");
route.get("/search/limit", SearchController.searchLimit);

the search function:

const Product = require("../models/Product");

const searchLimit = async (req, res) => {
  try {
    const { keywords } = req.query;
    keywords = keywords.toLowerCase();
    Product.findAll(
      { where: { keywords: { [Op.like]: "%" + term + "%" } } },
      { limit: 5 }
    )
      .then((output) => res.send("search result", { output }))
      .catch((error) => console.log(error));
  } catch (err) {
    coneole.log(err);
    return err;
  }
};

module.export = { searchLimit };

the error message:

Error: Route.get() requires a callback function but got a [object Undefined]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文