DEV Community

Gcobani Mkontwana
Gcobani Mkontwana

Posted on

How to solve this problem in nodejs?

Hi Team

I am trying to establish a connection to the database schema that does not use sql connection. I am using node js as the back end, while running this project, i get the following error below;

`PS C:\Users\gcobani\coding-challenge\backend> yarn dev

yarn run v1.22.22
warning ..\package.json: No license field
$ tsx watch src/index.ts
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

[Error: SQLITE_CANTOPEN: unable to open database file] {
errno: 14,
code: 'SQLITE_CANTOPEN'
}

Node.js v18.20.4`

// This is my typescript and file path on the VS code project

import { Sequelize } from 'sequelize';
import path from 'path';

// The dbPath should reflect the location of the winedrops.db file

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();
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more