Back

Help Needed: Invalid URL Errors with Appwrite Node SDK

  • 0
  • Tools
  • Web
shubham
9 Oct, 2024, 17:34

Hi everyone,

I'm currently working on initializing the backend using the Appwrite Node SDK and I've encountered some issues. When trying to interact with storage and databases, I'm receiving the following errors:

TypeScript
Error getting storage: [TypeError: Invalid URL] {
  code: 'ERR_INVALID_URL',
  input: '67065daa00265af52653/storage/buckets/question-attachment'
}
Error creating database: [TypeError: Invalid URL] {
  code: 'ERR_INVALID_URL',
  input: '67065daa00265af52653/databases'
}
Error creating storage: [TypeError: Invalid URL] {
  code: 'ERR_INVALID_URL',
  input: '67065daa00265af52653/storage/buckets'
}

It seems like there might be an issue with the URL format or configuration. I've double-checked my endpoint and project ID, but I'm still stuck. Could anyone provide guidance on what might be causing these errors or how to resolve them?

Thank you in advance for your help!

TL;DR
Developers are facing Invalid URL errors with the Appwrite Node SDK when interacting with storage and databases. The issue seems related to URL configuration. To solve it, make sure the endpoint and project ID are correctly set in the client configuration, specifically only set the endpoint once in the client initialization. Also, check the URL format being used for database and storage interactions.
faye
9 Oct, 2024, 17:46

Hey, how exactly are you doing the fetch? What does your client endpoint url look like?

shubham
9 Oct, 2024, 17:50

I have created a client with endpoint project id and api key after that create a database instance and calling the create method on it with all the neccecry parameter

shubham
9 Oct, 2024, 17:52
TypeScript
//config file
import { env } from "@/env";
import { Client, Avatars, Databases, Storage, Users } from "node-appwrite";

export const client = new Client();

client
  .setEndpoint(env.appwrite.endpoint)
  .setEndpoint(env.appwrite.projectId)
  .setKey(env.appwrite.apikey);

export const databases = new Databases(client);
export const avatars = new Avatars(client);
export const storage = new Storage(client);
export const users = new Users(client);
TypeScript
//db setup
import { db } from "../name";
import { createAnswerCollection } from "./answers.collection";
import { createCommentCollection } from "./comments.collection";
import { createQuestionCollection } from "./questions.collection";
import { createVoteCollection } from "./votes.collection";
import { databases } from "./config";

export const getOrCreateDB = async () => {
  try {
    await databases.get(db);
    console.log("database already exists");
    console.log("database connected");
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
  } catch (err) {
    try {
      await databases.create(db, db);
      console.log("database created");

      await Promise.all([
        createQuestionCollection(),
        createAnswerCollection(),
        createCommentCollection(),
        createVoteCollection(),
      ]);

      console.log("Collections created");
      console.log("database connected");
    } catch (error) {
      console.log("Error creating database: ", error);
    }

    return databases;
  }
};
faye
9 Oct, 2024, 17:57

you got 2x setEndpoint

faye
9 Oct, 2024, 17:57

so you are overwriting it with your projectid lol

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