#node environment

4 messages · Page 1 of 1 (latest)

wild tide
#

There is a thread about how to organize code between files that need a node environment and files that can run in the default Convex environment. Can you find that for me? There might be multiple threads talking about that.

zealous vortexBOT
#

Hi @wild tide. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, I can help you with that. There are indeed multiple discussions about organizing code between files that need a Node.js environment and files that can run in the default Convex environment. Here's a summary of the relevant information from the knowledge sources:

  1. The main way to use Node.js in Convex is by adding the "use node" directive at the top of a file. This is explained in the Functions > Runtimes > Node.js runtime (https://docs.convex.dev/functions/runtimes#nodejs-runtime) documentation. Files with this directive can only contain action functions and cannot include other Convex functions like queries or mutations.

  2. In a discussion about file organization, a community member suggested using a naming convention like <file>.ts for regular Convex functions and <file>Node.ts for files that need the Node.js environment. This approach is mentioned in the Discord support thread: Use Node only for specific actions (https://discord.com/channels/1019350475847499849/1247234873589104783).

  3. Another thread discusses the organization of files within the convex directory. It suggests grouping functions by logical entities and using the _ prefix for folders or files to exclude them from Convex function auto-generation. This is detailed in the Discord support thread: File based routing: How to organize files? (https://discord.com/channels/1019350475847499849/1240118627156492288).

  4. When using Node.js for specific actions, it's recommended to keep the Node.js code separate from regular Convex functions. You can call Node.js actions from other Convex functions using ctx.runAction(). This is explained in the Functions > Actions > Calling third-party APIs and using NPM packages (https://docs.convex.dev/functions/actions#calling-third-party-apis-and-using-npm-packages) documentation.

#

These sources provide different approaches to organizing code between Node.js and regular Convex environments, depending on your specific needs and project structure.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: