-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.js
executable file
·30 lines (29 loc) · 1.03 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require('dotenv/config');
// this file is what the express instance uses to auth to the appwrite service.
const sdk = require('node-appwrite');
const config = {
project: process.env.PROJECTID,
endpoint: process.env.ENDPOINT,
key: process.env.KEY,
// jwt: process.env.JWT // not in current .env
};
const client = new sdk.Client();
const database = new sdk.Database(client);
client
.setSelfSigned(true)
.setProject(config.project)
.setKey(config.key)
// .setJWT(config.jwt) // set this to authenticate using JWT
.setEndpoint(config.endpoint)
;
const collectionName = process.env.COLLECTIONNAME;
const read = [process.env.READ];
const write = [process.env.WRITE];
const promise = database.createCollection(collectionName, read, write);
promise.then(function(response) {
console.log('success');
database.createBooleanAttribute(response.$id, 'completed', true, false, false);
database.createStringAttribute(response.$id, 'text', 255, true, '', false);
}, function(error) {
console.log('error', error.type, error.message);
});