
大家好
我正在尝试建立与不使用 sql 连接的数据库模式的连接。我使用 node js 作为后端,在运行该项目时,出现以下错误;
`ps c:usersgcobanicoding-challengebackend> 纱线开发
纱线运行 v1.22.22
警告..package.json:没有许可证字段
$ tsx watch src/index.ts
节点:内部/进程/承诺:288
triggeruncaughtexception(err, true /* frompromise */);
^
[错误:sqlite_cantopen:无法打开数据库文件] {
错误号:14,
代码:'sqlite_cantopen'
}
node.js v18.20.4`
内容:生产级 Node.js 后端模式,涵盖 Express/Fastify 配置、分层架构、中间件、错误处理、验证、数据库集成、身份验证及缓存。 时机:构建 REST API、搭建 Node.js 服务器、实施身份验证、集成数据库、添加验证/缓存或构建后端应用结构时。 关键词:nodejs, node, express, fastify, typescript, api, rest, 中间件, 身份验证, jwt, 验证, zod, postgres, mongodb, redis, 缓存, 速率限
// 这是我在 vs code 项目上的打字稿和文件路径
从 'sequelize' 导入 { sequelize };
从“路径”导入路径;
// dbpath 应反映 winedrops.db 文件的位置
const dbPath = path.resolve(__dirname, 'db/winedrops.db'); // This should work if __dirname points to 'src'
console.log('Database path:', dbPath); // Log the path to confirm
export const sequelize = new Sequelize({
dialect: 'sqlite',
storage: dbPath,
});
async function testConnection() {
try {
await sequelize.authenticate();
console.log('Connection has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error.message);
}
}
testConnection();

















