Vârli
So I created a custom node.js server-side function and when I try to execute it i get an error that res.json
is undefined
here is the code
TypeScript
const sdk = require('node-appwrite');
module.exports = async function (req, res) {
const client = new sdk.Client();
const database = new sdk.Databases(client);
client
.setEndpoint('temp')
.setProject('temp');
try {
const response = await database.listDocuments('temp',
'temp');
return res.json({
myResponse: response,
});
} catch (error) {
console.log(error.toString());
return res.json({
myError: error.toString(),
endPoint: req.variables["APPWRITE_FUNCTION_ENDPOINT"],
projectId: req.variables["APPWRITE_FUNCTION_PROJECT_ID"],
functionApi: req.variables["APPWRITE_FUNCTION_API_KEY"],
});
}
}
TL;DR
Developers created a custom node.js server-side function but receive an error stating `res.json` is undefined. The issue lies in an incorrect implementation. The error occurs due to not properly passing `res` as a parameter. To fix the issue, ensure `res` is passed as a parameter to the function and remove the `return` statement before the problematic `res.json` calls. Recommended threads
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?
- Different appwrite IDs are getting expos...
File_URL_FORMAT= https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID] I'm trying to access files in my web app...
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...