Debugging
When building an application with @blocklet/server-js, you might encounter issues with API requests, authentication, or data fetching. To help you troubleshoot these problems, the client provides a detailed debugging log. This allows you to inspect the raw GraphQL queries being sent, the responses received, and other internal operations.
The library uses the popular debug utility, which allows for namespaced logging. You can enable these logs in both Node.js and browser environments.
In Node.js#
In a Node.js environment, you can enable debug logs by setting the DEBUG environment variable when you run your application. The @blocklet/server-js client uses the sdk:* namespace.
To see all debug output from the client, run your script like this:
Terminal
DEBUG="sdk:*" node your-app.jsThis command will print detailed information to your console, including the GraphQL queries, variables, and the results of each operation. This is incredibly useful for understanding exactly what data is being sent to and received from the Blocklet Server.
In the Browser#
To enable debugging in a web browser, you can use the Developer Tools console to set a localStorage item.
- Open your browser's Developer Tools (usually by pressing F12 or Cmd+Option+I).
- Select the Console tab.
- Execute the following JavaScript command:
Browser Console
localStorage.setItem('debug', 'sdk:*')After running the command, refresh the page. You will now see detailed debug messages from the @blocklet/server-js client logged in the console. This helps you inspect API calls and responses directly within the browser context.
To disable the logs, you can either clear the debug item or set it to an empty value:
Browser Console
localStorage.removeItem('debug')Using these debugging tools can significantly speed up the process of identifying and fixing issues in your application.