Local Development
Debug Cloud Functions
11 min
after creating and developing your application using parse cloud code functions, there’s always room for improvement when it comes to testing and debugging this guide will show you how to integrate your code editor with node js to debug your functions using a local parse server instance, simulating the back4app environment goal enable you to debug your parse cloud code locally in your preferred code editor 1 preparing your project files if you are already hosting your application on back4app or have set up cloud code via the dashboard, your project should follow this structure cloud directory contains the main js file where your cloud code functions are defined public directory holds your static content such as html and javascript files, typically including an index html file if your app is new or not yet deployed, replicate this structure to ensure the local parse server runs correctly 2 running your parse server locally to start a local instance of the parse server navigate to your project directory in the terminal run the following command to launch the server with a test database and your cloud code replace the placeholder values ( your app id , etc ) with random values avoid using your production keys verify that the server is running by opening http //localhost 1337/parse in your browser an "unauthorized" error means the server is running but the request lacks authentication keys 3 setting up and testing cloud code ensure all your cloud code functions are located in the cloud/main js file for example main js parse cloud define("debugtest", (request) => { return "testing!"; }); restart the parse server to load the new function now, test the function using curl in the terminal curl x post \\ h "x parse application id your app id" \\ h "x parse client key your client key" \\ http //localhost 1337/parse/functions/debugtest if configured correctly, the terminal will display the response "testing!" 4 debugging the code with node js you can use node js's debugging features, integrated with visual studio code (or a similar ide), to debug your functions step by step setting up vs code open the run and debug panel on the left sidebar and click create a launch json file choose node js as the environment this creates a basic debug configuration to enhance it click add configuration and select node js attach to process choose the attach by process id action and attach it to the parse server's node process debugging the code open main js and set a breakpoint on the line return "testing!"; by clicking to the left of the line number run the same curl command as before the debugger will pause execution at the breakpoint while paused, inspect environment variable values and the call stack in the debugger panel this approach lets you analyze your code’s behavior in detail conclusion by following this guide, you’ll be able to debug all aspects of your parse integration and cloud code functions locally, improving your development workflow with back4app