You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Node.js+Express的REST API调用MariaDB时出现solarData.getMultiple is not a function错误求助

Fixing "solarData.getMultiple is not a function" Error

Hey there! Let's break down why you're seeing this error and how to fix it quickly.

The Root Cause

The error happens because you've defined the getMultiple function in ./services/solarData.js, but you haven't exported it. When your route file (./routes/solarData.js) imports solarData, it's getting an empty object instead of the function you wrote.

The Fix

Add an export statement at the very end of ./services/solarData.js to make the getMultiple function available to other files:

const db = require('./db');
const helper = require('../helper');
const config = require('../config');

async function getMultiple(page = 1){
  const offset = helper.getOffset(page, config.listPerPage);
  const rows = await db.query(
    `SELECT idxDTP, year(DT) AS Year, month(DT) AS Month, day(DT) AS Day, hour(DT) AS Hour, minute(DT) AS Min, PWR AS Power FROM DTP WHERE (DT >= '2021-01-12 12:30:00') AND (DT <= '2021-01-12 12:40:00') ORDER BY Year ASC, Month ASC, Day ASC, Hour ASC, Min ASC LIMIT ?,?`,
    [offset, config.listPerPage]
  );
  const data = helper.emptyOrRows(rows);
  const meta = {page};
  return {
    data,
    meta
  }
}

// Add this line to export the function
module.exports = { getMultiple };

Additional Checks to Ensure Everything Works

  • Verify File Paths: Double-check that require('../services/solarData') in your route file points to the correct location of solarData.js. A wrong relative path can also lead to importing an empty module.
  • Restart Your Server: After making this change, stop and restart your Node.js server to ensure the updated module is loaded.
  • Check Helper Functions: Make sure your helper.js file (which you import in solarData.js) has the getOffset and emptyOrRows functions defined correctly—this will prevent future errors once the export issue is fixed.

Once you apply the export fix, your /solarData endpoint should be able to call getMultiple successfully and return the database data as JSON.

内容的提问来源于stack exchange,提问作者Greg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 08:39:08