Back

node-appwrite database is not a function

  • 0
  • Databases
zombikaa
30 Nov, 2024, 07:24

Hi, I am using express and i'm getting an error with the database.createDocument: {"success":false,"message":"database.createDocument is not a function"}

This only shows if i want to import the database from another file, the config file is looking like this now:

TypeScript
import { Client, Databases } from 'node-appwrite';

const client = new Client();

client
  .setEndpoint(process.env.APPWRITE_ENDPOINT)  
  .setProject(process.env.APPWRITE_PROJECT_ID) 
  .setKey(process.env.APPWRITE_API_KEY); 

export const database = new Databases(client);

And im importing it like this: import { database } from '../config/appwrite.js'; and i get the error

The weird thing is the documents are being created, but the error is not dissapearing.

TL;DR
Issue: Error message "database.createDocument is not a function" when trying to import database from another file in an Express app using node-appwrite. Solution: Include the creation of database instance directly in the main file instead of importing it, like this: ```javascript const client = new Client() .setEndpoint(process.env.APPWRITE_ENDPOINT) .setProject(process.env.APPWRITE_PROJECT_ID) .setKey(process.env.APPWRITE_API_KEY); export const database = new Databases(client); ```
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more