zwarag\\harrysOriginal post
Rank 1: Thread
Hi I'm trying out appwrite functions. So I created the following function with appwrite function init and deployed it with appwrite function deploy. However I cannot see the log seems to be empty?
JavaScript
const sdk = require("node-appwrite");
module.exports = async function (req, res) { const client = new sdk.Client();
const account = new sdk.Account(client); const database = new sdk.Databases(client); const teams = new sdk.Teams(client); const users = new sdk.Users(client);
if ( !req.variables['APPWRITE_FUNCTION_ENDPOINT'] || !req.variables['APPWRITE_FUNCTION_API_KEY'] ) { console.warn("Environment variables are not set. Function cannot use Appwrite SDK."); } else { client .setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT']) .setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID']) .setKey(req.variables['APPWRITE_FUNCTION_API_KEY']) .setSelfSigned(true); console.log(req); // I'd have hoped this logs? }
res.json({ areDevelopersAwesome: true, });};Summary
The user created an Appwrite function but can't see the console.log output. They tried logging 'req' but it's not working. The user added the log in the wrong place. Instead of logging 'req' inside the if block, they should log it outside the if-else block.
Here is the corrected code:
```js
const sdk = require("node-appwrite");
module.exports = async function (req, res) {
const client = new sdk.Client();
const account = new sdk.Account(client);
const database = new sdk.Databases(client);
const teams = new sdk.Teams(client);
const
