Checking The Size Of A Site

This is a simple API Test which gets the Google homepage and fails if the size of the body is greater than or equal to 200000 bytes.

var assert = require('assert');

$http.get('http://google.com',

 // Callback
  function (err, response, body) {
        console.log(Buffer.byteLength(body, 'utf8') + " bytes");
        assert.ok(Buffer.byteLength(body, 'utf8') < 200000, "Body was larger than 200kB");
  }
);
1 Like