Docs
Debugging

Debugging

Debug your APIs directly in the server with built-in support for console.log() and other logging methods. MaskAPI makes it easy to inspect values, trace issues, and understand exactly what's happening inside your API logic without setting up external logging tools or servers.


📘 What is Debugging in MaskAPI?

in MaskAPI Studio, You can use standard JavaScript logging functions inside your MaskAPI endpoint code, such as:

  • console.log()

  • console.error()

  • console.clear()

All log output is captured and shown in the MaskAPI Studio, allowing you to trace what happens step by step.


🛠 How to Debug Your Endpoint

If you'd like to connect all endpoints in your project to a single database, follow these steps:

  1. Select your endpoint

  2. Go to the "Code" tab

  3. write your logic and add console.log() or any other logging statements

  4. Click "Run Mask" on the top of the page

  5. Go to the "Console" tab in "Response" section

  6. View your debug logs under the "Output" tab


✅ Example

Here’s an example using PostgreSQL:

return (async function (connection, maskRoutes, maskQueries, maskRequestHeaders, maskRequestBody){
  const { rows } = await connection.query(`SELECT * FROM users;`);
  console.log('rows', rows[0]);
 
  return {
    responseBody: {
      result: rows,
    },
    responseHeaders: {
      'content-type': 'application/json'
    },
    statusCode: 200
  }
})(connection, maskRoutes, maskQueries, maskRequestHeaders, maskRequestBody);

🔍 Sample Output

After clicking "Run Mask", go to the Console → Output tab and you’ll see something like:

rows {
  id: 1,
  name: "Alice Johnson",
  email: "alice@example.com",
  password: "hashed_pw_123",
  role: "customer"
}

🧠 Best Practices

  • Use console.log() to inspect values like request headers, body, route params, or query params.

  • Use console.error() for catching and displaying specific error cases.

  • Use console.clear() to remove noise during repeated testing.