Back

ID import for server function

  • 0
  • Functions
Capone
4 May, 2023, 20:05

Hey, I am trying to create a basic server function in nodejs that just makes a collection in the database with a unique id.

How would I import id using the same method i have used to import the other modules that you can see in the attachment.

Thanks

TL;DR
To import the `ID` module in Node.js, you can use the following code: ``` const { ID } = require('appwrite'); ``` This will allow you to use the `ID.unique()` function to generate a unique ID for your collection. Solution: Import the `ID` module using the provided code and then use `ID.unique()` to generate a unique ID for your collection.
safwan
4 May, 2023, 20:30

If all you want to do is create a new collection with a unique ID, you can do this

TypeScript
let client = new api.Client();
let database = new api.Databases(client);

client
  .setEndpoint('[ENDPOINT-HERE]')
  .setProject('[PROJECT-ID]')
  .setKey('[API-KEY-HERE]')

const promise = databases.createCollection('[DATABASE_ID]', ID.unique(), '[NAME]');

ID.unique() is a helper function that comes with the appwrite SDK, which generates a unique ID for you.

Reference: https://appwrite.io/docs/server/databases?sdk=nodejs-default#databasesCreateCollection

safwan
4 May, 2023, 20:31

If you need something more than just this, let me know!

jSnake🐍🕊
5 May, 2023, 09:56

with your import it would be api.ID.unique()

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