You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**This SDK is compatible with Appwrite server version 1.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-node/releases).**
9
+
**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-node/releases).**
10
10
11
11
> This is the Node.js SDK for integrating with Appwrite from your Node.js server-side code.
12
12
If you're looking to integrate from the browser, you should check [appwrite/sdk-for-web](https://github.com/appwrite/sdk-for-web)
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page and your new API secret Key project API keys section.
31
32
32
33
```js
@@ -43,6 +44,7 @@ client
43
44
```
44
45
45
46
### Make Your First Request
47
+
46
48
Once your SDK object is set, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section.
The Appwrite Node SDK provides type safety when working with database documents through generic methods. Methods like `listDocuments`, `getDocument`, and others accept a generic type parameter that allows you to specify your custom model type for full type safety.
console.log(`Book: ${book.name} by ${book.author}`); // Now you have full type safety
110
+
});
111
+
} catch (error) {
112
+
console.error('Appwrite error:', error);
113
+
}
114
+
```
115
+
116
+
**JavaScript (with JSDoc for type hints):**
117
+
```javascript
118
+
/**
119
+
* @typedef{Object}Book
120
+
* @property{string}name
121
+
* @property{string}author
122
+
* @property{string}[releaseYear]
123
+
* @property{string}[category]
124
+
* @property{string[]}[genre]
125
+
* @property{boolean}isCheckedOut
126
+
*/
127
+
128
+
constdatabases=newDatabases(client);
129
+
130
+
try {
131
+
/**@type{Models.DocumentList<Book>}*/
132
+
constdocuments=awaitdatabases.listDocuments(
133
+
'your-database-id',
134
+
'your-collection-id'
135
+
);
136
+
137
+
documents.documents.forEach(book=> {
138
+
console.log(`Book: ${book.name} by ${book.author}`); // Type hints available in IDE
139
+
});
140
+
} catch (error) {
141
+
console.error('Appwrite error:', error);
142
+
}
143
+
```
144
+
145
+
**Tip**: You can use the `appwrite types` command to automatically generate TypeScript interfaces based on your Appwrite database schema. Learn more about [type generation](https://appwrite.io/docs/products/databases/type-generation).
146
+
83
147
### Error Handling
148
+
84
149
The Appwrite Node SDK raises `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching `AppwriteException` and present the `message` to the user or handle it yourself based on the provided error information. Below is an example.
0 commit comments