
I want to test my nodejs funtion before I deploy it to git. Im using V1.4.2 and node-18.
How I can run the function to test the functionality?

It's easiest to just deploy it to Appwrite. You can deploy to a local Appwrite instance. Or, you can deploy to your prod project but with a different function Id.
Technically, it's also possible to run the open Runtimes container yourself: https://github.com/open-runtimes/open-runtimes/tree/main/runtimes/node-18.0#usage

I find an another way to do it. Simple and fast:
- create a file like local-test.mjs in /src
- With the content content:
// local-test.mjs
import main from './main.js'; // Assuming 'main.js' is in the same directory
import dotenv from 'dotenv';
dotenv.config();
// Simulate the req and res objects
const req = {
method: 'GET', // Change this to 'POST' if needed
};
const res = {
send: (data) => {
console.log(data);
},
json: (data) => {
console.log(JSON.stringify(data, null, 2));
},
};
const log = console.log;
const error = console.error;
// Execute the main script
main({ req, res, log, error });
- Start it with the command:
node --experimental-modules src/local-test.mjs
Now, you have the respnse, logs, errors, etc like in appwrite console 🙂

You may run into problems where it works locally, but not in Appwrite. I always feel like working incrementally and deploying to Appwrite is the best approach to make sure things work.

Of corse, but during devolopment its not so good deploy always to appwrite to test only 1 change. Its take to much time. Therefore Im looking something to test localy.

It typically takes 30 seconds or so to deploy for me.
A local instance of Appwrite could be faster too

Could be 🙂 But I have some functions also in prod. I can not deploy any changes before testing. That is my pain point

Can't you deploy a duplicate function (different id)?

Although local instance is a better approach

thats possible, thanks. I can do both.
Recommended threads
- appwrite.json - "variables" not deployin...
Hi, I have self-hosted Appwrite v1.7.4 and the latest Appwrite CLI. I cannot get the "variables" in the appwrite.json to deploy. I am using this format: ...
- Migrate IDs
Hi everyone, is it possible to migrate entries with an ID to another ID (like just change the ID of e.g. a database, collection, bucket, etc.)? I could write a ...
- Bulk API upsert or Create documents func...
Hi , I keep getting “databases.upsertDocuments” or “createDocuments” function is not a valid appwrite function error . Following is a simple node.js code (modi...
