Mock Server

Debug mock server scripts

Our mock server scripts are written in native JavaScript, which allows for easy debugging using the console.log() function. Keep in mind that when logging JSON objects, it is necessary to use the JSON.stringify() method to convert the object to a string before logging it to the console. These logs will be associated with each corresponding HTTP request and can be reviewed in the request logs for further analysis.

As an example, adding console logs to the route callback functions can be done like this:

// use console.log(...) to print logs to console for debugging,
// the only thing you need to pay attention to is console.log(...) 
// only access arguments of string, number, bool.
// if you would like to print a Json object, 
// you need to conver it to string by JSON.stringify() first. 
// here is the example:
mock.define("/example", "GET", function(req, res) {
  console.log("hello world, this is a debug message");
  console.log("hello", "world", true);
  console.log(JSON.stringify({hello:"hello", world:"world"}, null, 4));
  var users = [ 
    { username: "hello", email: "" },
    { username: "world", email: "" }
  // JSON.stringify to convert json to string first
  console.log(JSON.stringify(users, null, 4));

You will be able to view the console logs in the detailed log for each request: review console log