{"id":21297493,"url":"https://github.com/fvdm/nodejs-gtmetrix","last_synced_at":"2025-07-11T18:32:28.478Z","repository":{"id":48318508,"uuid":"43861888","full_name":"fvdm/nodejs-gtmetrix","owner":"fvdm","description":"Node.js module for the GTmetrix API to run and access tests","archived":false,"fork":false,"pushed_at":"2021-10-22T15:50:51.000Z","size":160,"stargazers_count":40,"open_issues_count":0,"forks_count":7,"subscribers_count":6,"default_branch":"develop","last_synced_at":"2025-06-06T18:04:56.374Z","etag":null,"topics":["api","debug","gtmetrix","nodejs","unlicense","webdev"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/gtmetrix","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fvdm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://fvdm.com/donating"}},"created_at":"2015-10-08T04:02:27.000Z","updated_at":"2025-05-09T08:58:03.000Z","dependencies_parsed_at":"2022-09-26T16:32:13.477Z","dependency_job_id":null,"html_url":"https://github.com/fvdm/nodejs-gtmetrix","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/fvdm/nodejs-gtmetrix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fvdm%2Fnodejs-gtmetrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fvdm%2Fnodejs-gtmetrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fvdm%2Fnodejs-gtmetrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fvdm%2Fnodejs-gtmetrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fvdm","download_url":"https://codeload.github.com/fvdm/nodejs-gtmetrix/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fvdm%2Fnodejs-gtmetrix/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260406248,"owners_count":23004121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","debug","gtmetrix","nodejs","unlicense","webdev"],"created_at":"2024-11-21T14:37:43.528Z","updated_at":"2025-07-11T18:32:28.119Z","avatar_url":"https://github.com/fvdm.png","language":"JavaScript","readme":"# gtmetrix\n\nNode.js module for the GTmetrix API to run and access tests.\n\n[![npm](https://img.shields.io/npm/v/gtmetrix.svg?maxAge=3600)](https://github.com/fvdm/nodejs-gtmetrix/blob/master/CHANGELOG.md)\n[![Build Status](https://github.com/fvdm/nodejs-gtmetrix/actions/workflows/node.js.yml/badge.svg?branch=master)](https://github.com/fvdm/nodejs-gtmetrix/actions/workflows/node.js.yml)\n[![Coverage Status](https://coveralls.io/repos/github/fvdm/nodejs-gtmetrix/badge.svg?branch=master)](https://coveralls.io/github/fvdm/nodejs-gtmetrix?branch=master)\n\n* [Node.js](https://nodejs.org)\n* [GTMetrix](https://gtmetrix.com)\n* [API documentation](https://gtmetrix.com/api/)\n\n\n## Example\n\n```js\nconst gtmetrix = require ('gtmetrix') ({\n  email: 'your@mail.tld',\n  apikey: 'abc123'\n});\n\n// Run test from London with Google Chrome\nconst testDetails = {\n  url: 'http://example.net/',\n  location: 2,\n  browser: 3\n};\n\n// Poll test every 5 seconds for completion, then log the result\ngtmetrix.test.create (testDetails).then (data =\u003e\n  gtmetrix.test.get (data.test_id, 5000).then (console.log));\n```\n\n_(For readability I left out the error handling)_\n\n\n## Installation\n\n`npm i gtmetrix`\n\nYou need an account at GTmetrix to get an API key.\nThe API key can be found [here](https://gtmetrix.com/api/#api-details) when you\nare logged in.\n\n\n## Configuration\n\nThe setup function takes an _object_ with these settings.\n\nname    | type    | required | default | description\n:-------|:--------|:---------|:--------|:--------------------\nemail   | string  | yes      |         | Your account email\napikey  | string  | yes      |         | Your account API key\ntimeout | int     | no       | 5000    | Wait timeout in ms\n\n\n#### Example\n\n```js\nconst gtmetrix = require ('gtmetrix') ({\n  email: 'your@mail.tld',\n  apikey: 'abc123',\n  timeout: 10000\n});\n```\n\n\n## Methods\n\nAll methods return promises, but you can also provide a callback function\ninstead which gets the standard `err` and `data` arguments.\n\nIn the examples below I use a mix of callbacks and promises, but each method\ncan do both. I also left out the error handling for better readability.\n\n\n#### Errors\n\nmessage          | description            | properties\n:----------------|:-----------------------|:----------------------------------\nrequest failed   | Request cannot be made | `error`\ninvalid response | Can't process response | `error` `statusCode` `contentType`\nAPI error        | API returned an error  | `error` `statusCode` `contentType`\n\n\n### test.create\n**( params, [callback] )**\n\nRun a test.\n\nargument | type     | required | description\n:--------|:---------|:---------|:-----------------\nparams   | object   | yes      | Test settings\ncallback | function | no       | `(err, data)` or promise\n\n[API documentation](https://gtmetrix.com/api/#api-test-start)\n\n\n```js\n// Run test from London with Google Chrome\nconst test = {\n  url: 'http://example.net/',\n  location: 2,\n  browser: 3\n};\n\ngtmetrix.test.create (test, console.log);\n```\n\n```js\n{ credits_left: 68,\n  test_id: 'Ao0AYQbz',\n  poll_state_url: 'https://gtmetrix.com/api/0.1/test/Ao0AYQbz' }\n```\n\n\n### test.get\n**( testId, [resource], [polling], [callback] )**\n\nGet details about a test or one of its resources.\n\nWhen you specify a binary resource, i.e. `screenshot`,\nthe callback `data` will be a _Buffer_ instance, so you can\npost-process the binary data however you like. See example below.\n\nargument | type     | required | description\n:--------|:---------|:---------|:-----------------------------\ntestId   | string   | yes      | Test `id` to look up\nresource | string   | no       | Retrieve a test resource\npolling  | int      | no       | Retry until completion, in ms\ncallback | function | no       | `(err, data)` or promise\n\n[API documentation](https://gtmetrix.com/api/#api-test-state)\n\n\n#### Test details\n\nGet what is currently available, without waiting for completion.\n\n```js\ngtmetrix.test.get ('Ao0AYQbz', console.log);\n```\n\n```js\n{ resources: {}, error: '', results: {}, state: 'started' }\n```\n\n\nWait for completion and then get the details.\n\n```js\n// Retry every 5 seconds (5000 ms)\ngtmetrix.test.get ('Ao0AYQbz', 5000, console.log);\n```\n\n```js\n{ resources:\n   { report_pdf: 'https://gtmetrix.com/api/0.1/test/Ao0AYQbz/report-pdf',\n     pagespeed: 'https://gtmetrix.com/api/0.1/test/Ao0AYQbz/pagespeed',\n     har: 'https://gtmetrix.com/api/0.1/test/Ao0AYQbz/har',\n     pagespeed_files: 'https://gtmetrix.com/api/0.1/test/Ao0AYQbz/pagespeed-files',\n     report_pdf_full: 'https://gtmetrix.com/api/0.1/test/Ao0AYQbz/report-pdf?full=1',\n     yslow: 'https://gtmetrix.com/api/0.1/test/Ao0AYQbz/yslow',\n     screenshot: 'https://gtmetrix.com/api/0.1/test/Ao0AYQbz/screenshot' },\n  error: '',\n  results:\n   { onload_time: 185,\n     first_contentful_paint_time: 221,\n     page_elements: 2,\n     report_url: 'https://gtmetrix.com/reports/example.net/Ao0AYQbz',\n     redirect_duration: 0,\n     first_paint_time: 221,\n     dom_content_loaded_duration: null,\n     dom_content_loaded_time: 184,\n     dom_interactive_time: 183,\n     page_bytes: 1911,\n     page_load_time: 185,\n     html_bytes: 277,\n     fully_loaded_time: 307,\n     html_load_time: 145,\n     rum_speed_index: 221,\n     yslow_score: 99,\n     pagespeed_score: 99,\n     backend_duration: 68,\n     onload_duration: 0,\n     connect_duration: 77 },\n  state: 'completed' }\n```\n\n\n#### Retrieve screenshot\n\nRetry every 5000 ms until it's ready.\n\n```js\nconst fs = require ('fs');\n\ngtmetrix.test.get ('Ao0AYQbz', 'screenshot', 5000).then (data =\u003e\n  fs.writeFile (__dirname + '/screenshot.jpg', data, console.log));\n```\n\n\n##### Resources\n\nresource        | binary | content   | description\n:---------------|:-------|:----------|:---------------------------------------\nfilmstrip       | yes    | JPEG      | Page loading filmstrip (requires video)\nhar             | no     | JS object | HTTP Archive\npagespeed       | no     | JS object | Pagespeed report\npagespeed-files | yes    | ZIP       | Pagespeed optimized files\nreport-pdf      | yes    | PDF       | Test summary\nreport-pdf-full | yes    | PDF       | Full test report\nscreenshot      | yes    | JPEG      | Screenshot image\nvideo           | yes    | MP4       | Page loading video\nyslow           | no     | JS object | YSlow report\n\n\n### locations.list\n**( [callback] )**\n\nGet a list of available test locations.\n\nargument | type     | required | description\n:--------|:---------|:---------|:------------------------\ncallback | function | no       | `(err, data)` or promise\n\n[API documentation](https://gtmetrix.com/api/#api-locations)\n\n\n```js\ngtmetrix.locations.list (console.log);\n```\n\n```js\n[ { name: 'Vancouver, Canada',\n    default: true,\n    id: '1',\n    browsers: [ 1, 3 ] } ]\n```\n\n\n### browsers.list\n**( [callback] )**\n\nGet a list of available test browsers.\n\nargument | type     | required | description\n:--------|:---------|:---------|:------------------------\ncallback | function | no       | `(err, data)` or promise\n\n[API documentation](https://gtmetrix.com/api/#api-browsers)\n\n\n```js\ngtmetrix.browsers.list (console.log);\n```\n\n```js\n[ { features:\n     { dns: true,\n       cookies: true,\n       adblock: true,\n       http_auth: true,\n       video: true,\n       user_agent: true,\n       throttle: true,\n       filtering: true,\n       resolution: true },\n    browser: 'firefox',\n    name: 'Firefox (Desktop)',\n    platform: 'desktop',\n    id: 1,\n    device: '' } ]\n```\n\n\n### browsers.get\n**( browserId, [callback] )**\n\nGet details about a test browser.\n\nargument  | type     | required | description\n:---------|:---------|:---------|:-----------------------\nbrowserId | int      | yes      | Browser to look up\ncallback  | function | no       | `(err, data)` or promise\n\n[API documentation](https://gtmetrix.com/api/#api-browsers-details)\n\n\n```js\ngtmetrix.browsers.get (3, console.log);\n```\n\n```js\n{ features:\n   { dns: true,\n     cookies: true,\n     adblock: true,\n     http_auth: true,\n     video: true,\n     user_agent: true,\n     throttle: true,\n     filtering: true,\n     resolution: true },\n  browser: 'chrome',\n  name: 'Chrome (Desktop)',\n  platform: 'desktop',\n  id: 3,\n  device: '' }\n```\n\n\n### account.status\n**( [callback] )**\n\nInformation about your account.\n\nargument   | type     | description\n:----------|:---------|:-----------\n[callback] | function | `(err, data)` or promise\n\n[API documentation](https://gtmetrix.com/api/#api-status)\n\n\n```js\ngtmetrix.account.status (console.log);\n```\n\n```js\n{ api_refill: 1234567890, api_credits: 68 }\n```\n\n\n## Unlicense\n\nThis is free and unencumbered software released into the public domain.\n\nAnyone is free to copy, modify, publish, use, compile, sell, or\ndistribute this software, either in source code form or as a compiled\nbinary, for any purpose, commercial or non-commercial, and by any\nmeans.\n\nIn jurisdictions that recognize copyright laws, the author or authors\nof this software dedicate any and all copyright interest in the\nsoftware to the public domain. We make this dedication for the benefit\nof the public at large and to the detriment of our heirs and\nsuccessors. We intend this dedication to be an overt act of\nrelinquishment in perpetuity of all present and future rights to this\nsoftware under copyright law.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR\nOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\nARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\nFor more information, please refer to \u003chttps://unlicense.org\u003e\n\n\n## Author\n\n[Franklin](https://fvdm.com)\n| [Buy me a coffee](https://fvdm.com/donating)\n","funding_links":["https://fvdm.com/donating"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffvdm%2Fnodejs-gtmetrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffvdm%2Fnodejs-gtmetrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffvdm%2Fnodejs-gtmetrix/lists"}