Skip to Content
This documentation is still under construction
Node.js APIConnect

Connecting to a database in Node.js

Install the package for PostgreSQL (npm i @w-kuipers/alphadb-postgres) and import the database class.

import AlphaDB from "@w-kuipers/alphadb";

Initialize an instance and connect it to a database using your database credentials.

const db = new AlphaDB(); db.connect({ host: "localhost", user: "user", password: "password", database: "database", port: 5432, })

It might be a good idea to run this in an async function so that the connection can be awaited before any other methods are called.

const connect = async() => { const db = new AlphaDB(); await db.connect({ host: "localhost", user: "user", password: "password", database: "database", port: 5432, }) }

Using MySQL? Install @w-kuipers/alphadb-mysql instead and use port 3306.

Replace the credentials with your own. AlphaDB requires the user to have the following privileges: CREATE, INSERT, DELETE, SELECT, UPDATE, ALTER, DROP and REFERENCES.

Last updated on