Hi, I wrote a simple app for Functions, just to get and list the attributes, but I cannot get anything on the console, app is finishing OK (green light). apikey has enabled all permissions.
const sdk = require('node-appwrite');
module.exports = async function (req, res) { const client = new sdk.Client();
client
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('6411d...8abc')
.setKey('1cc9a39ba9f39f93...de2eac30e3')
//.setSelfSigned(true);
;
const database = new sdk.Databases(client);
const promise = database.listAttributes('648...342', '648...859').then(
(response) => {
console.log(response);
response.attributes.forEach((val) => {
console.log(val.key);
});
},
(err) => {
console.log(err);
res.json({ error: err });
}
);
promise.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});
res.json({ completed: true }); };
Also, when I run body only of the function() locally in VSC, I get what I want on console.log.
Your function is probably completing before the console.log() gets executed. I highly suggest using async/try/await/catch instead of then. Either that, or you can await your promise or call res.json inside the callbacks.
Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting
Thank you. I will check this now.
This did the trick, thanks again.
try {
const promise = await database.listAttributes('6483...342', '648...859');
promise.attributes.forEach((val) => {
console.log(val.key);
});
} catch(error) {
res.json({ error: err });
}
[SOLVED] Nothing on the console.log
Recommended threads
- Invalid token passed in the request
Hello, I have an issue using updateMagicURLSession. I send the email using sendMagicLink, which works fine. When i click the link in the email i get the invali...
- how can i make a relationship between a ...
i want to relate the $id from users auth table in appwrite with other column in my table user_profile. because is the same user... how can i have exactly the s...
- Google login on mobile not working
Hi the gg login auth in mobile not working. No error show. But the user couldnt login in Attached is the video. Desktop is working well and im using custom doma...