FlipFlip
FlipFlip3d ago

Best Practices for Project Structure

I started using Convex 2 days ago and couldn't find any documentation on project structure. I learnt that I have to use "use node"; for files that contain actions that aren't in the root directory but then I wasn't sure if that's how I'm supposed to structure the project. Am I overthinking this or am I missing something big? Would love some thoughts!
No description
5 Replies
Nicolas
Nicolas3d ago
I learnt that I have to use "use node"; for files that contain actions that aren't in the root directory
This doesn't sound accurate, you need to use "use node" if you want to use Node actions (https://docs.convex.dev/functions/runtimes#nodejs-runtime), the directory doesn't matter
Runtimes | Convex Developer Hub
Convex functions can run in two runtimes:
Nicolas
Nicolas3d ago
We don't have official guidance on how to structure projects, but what you're doing looks good!
FlipFlip
FlipFlipOP2d ago
@Nicolas I looked at the error again
✖ actions/continueThread.ts is in /actions subfolder but has no "use node"; directive. You can now define actions in any folder and indicate they should run in node by adding "use node" directive. /actions is a deprecated way to choose Node.js environment, and we require "use node" for all files within that folder to avoid unexpected errors during the migration. See https://docs.convex.dev/functions/actions for more details
✖ actions/continueThread.ts is in /actions subfolder but has no "use node"; directive. You can now define actions in any folder and indicate they should run in node by adding "use node" directive. /actions is a deprecated way to choose Node.js environment, and we require "use node" for all files within that folder to avoid unexpected errors during the migration. See https://docs.convex.dev/functions/actions for more details
And then I renamed the folder from /actions to /action and it worked fine without use node;. Weird but it fixed it!
Nicolas
Nicolas2d ago
Interesting, I didn't know about this legacy behavior! So yes this is something that we don't support anymore. But if you don't need the Node runtime feel free to do that!
FlipFlip
FlipFlipOP2d ago
I’ve removed it! Thank you!

Did you find this page helpful?