javascript - TypeError:“config.server”属性是必需的,并且必须是 NodeJS 中的字符串类型
问题描述
我正在尝试使用 NodeJS 中的 mssql 包从 MSSQL 数据库中获取查询。当我运行我的代码时,会出现错误。另外问题是该错误仅出现在生产中,在开发中它可以正常工作!:(
这是我的代码
const { Router } = require('express');
const { config } = require("../database/config");
const sql = require("mssql");
router.post("/", (req, res) => {
const {data1, data2} = req.body
const query = `The Query is too long but it works!`
switch (data1) {
case 'subdata1':
// Making the connection to MMSQL
const pool1 = new sql.ConnectionPool(Config);
const poolConnect = await pool1.connect() // The trace error indicates that the problem is in this line
// ^^^ exactly here
async function data1Path() {
await poolConnect;
try {
const request = await pool1.request();
const result = await request.query(query);
// Handling the query result
return result.recordset[0].Direccion.replace(/\\/g, "/");
} catch (error) {
console.log("SQL Error: ", error);
};
};
const getData1Query = await data1Path(); // Getting the path to find the file
}
case 'subdata2':
// doing another things...
})
下一个代码是我的数据库配置文件,我用 module.exports 导出它:
const config = {
server: DB_HOST,
port: 1433,
user: DB_USER,
password: DB_PASSWORD,
database: "my_db_name",
connectionTimeout: 180000,
driver: "tedious",
stream: "true",
options: {
appName: APP_NAME,
encrypt: false,
enableArithAbort: true,
},
pool: {
max: 70,
min: 0,
idTimeoutMillis: 30000,
log: true,
},
};
我一直在测试和测试,我找不到什么问题。我希望你能帮助我,我会非常感激<3 :(
解决方案
推荐阅读
- twitter-bootstrap - DropDownListFor()设置宽度超过300px MVC 5的问题
- java - 如何进行循环延迟?(JavaFX)
- html - 如何使一个 div 垂直滚动,而另一个不具有两个 inline-block div?
- html - 如何通过 HTML 代码在 MVC 中绑定我的模型?
- entity-framework - Entity Framework 2.1 映射的问题
- d3.js - d3-fetch 和 UTF-16 LE
- windows - 如何在 Windows 10 上重置密码列表
- java - 集合、单例、垃圾回收
- c# - Xamarin Forms 中的异步 Web 服务请求使用使用回调的公司库
- arrays - 如果你有一个对象的对象,哪个类是可比较的?