# WebPageTest API Wrapper for NodeJS
[](https://www.npmjs.org/package/webpagetest)
[](https://www.npmjs.org/package/webpagetest)
WebPageTest API Wrapper is a [NPM](https://npmjs.org) package that wraps [WebPageTest](https://github.com/WPO-Foundation/webpagetest) API for [NodeJS](https://nodejs.org) as a module and a command-line tool.
For a better understanding of WebPageTest API Wrapper, here are some sample [Node Recipies](https://github.com/WebPageTest/WebPageTest-API-Recipes)
## Getting started
```bash
npm install webpagetest -g
```
## Basics
### Command line
```bash
webpagetest test https://docs.webpagetest.org/api/integrations/ -k YOURAPIKEY
```
### Docker
#### Build
```bash
docker build -t webpagetest-api .
```
#### Run
```bash
docker run -it --rm webpagetest-api -k YOURAPIKEY test https://docs.webpagetest.org/api/integrations/
```
### Module
```javascript
const WebPageTest = require("webpagetest");
const wptServer = "www.webpagetest.org";
const wpt = new WebPageTest(wptServer, "YOUR_API_KEY");
const siteToTest = "https://docs.webpagetest.org/api/integrations/";
wpt.runTest(siteToTest, (err, data) => {
console.log(err || data);
});
```
## Command Line
### Help
```bash
webpagetest --help
```
### Commands
- **status** _[options] \_: check test status
- **results** _[options] \_: get test results
- **locations** _[options]_: list locations and the number of pending tests
- **testers** _[options]_: list testers status and details
- **test** _[options] \_: run test, _\_ can also be a path to a script file
- **testAndWait** _[options] \_: run test and waits for the result, _\_ can also be a path to a script file
- **testBalance** _[options]_: get remaining tests for the account
- **restart** _\_: restart test
- **cancel** _\_: cancel running/pending test
- **har** _\_: get the HTTP Archive (HAR) from test
- **pagespeed** _[options] \_: get the Google Page Speed results (if available) from test
- **utilization** _[options] \_: get the CPU, bandwidth and memory utilization data from test
- **request** _[options] <\id\>_: get the request data from test
- **timeline** _[options] \_: get the Chrome Developer Tools Timeline data (if available) from test
- **netlog** _[options] \_: get the Chrome Developer Tools Net log data (if available) from test
- **chrometrace** _[options] \_: get the Chrome Trace data (if available) from test
- **console** _[options] \_: get the browser console log data (if available) from test
- **testinfo** _\_: get test request info/details
- **history** _[days]_: get history of previously run tests
- **googlecsi** _[options] \_: get Google CSI data (Client Side Instrumentation)
- **response** _[options] \_: get response body for text resources
- **waterfall** _[options] \_: get the waterfall PNG image
- **screenshot** _[options] \_: get the fully loaded page screenshot in JPG format (PNG if in full resolution)
- **video** _[options] \_: create a video from _\_ (comma separated test ids)
- **player** _\_: get a html5 player for a video _\_
- **listen** _[options]_ _[port]_: start webpagetest-api server on port _[7791_]
- **batch** _\_: run commands in batch, i.e. one command per line from _\_ in parallel
### Options
#### Common (works for all commands)
- **-s, --server** _\_: the WPT server URL [https://www.webpagetest.org]
- **-d, --dryrun**: just return the RESTful API URL
- **-o, --out** _\_: place the output into \. Defaults to stdout
- **--http_method** _\_: the HTTP method to use (GET, POST) [GET]
_The default WPT server can also be specified via environment variable `WEBPAGETEST_SERVER`_
#### Test (works for **test** command only)
- **-l, --location** _\_: location to test from
- **-y, --connectivity** _\_: connectivity profile -- requires location to be specified -- (Cable|DSL|3GSlow|3G|3GFast|4G|LTE|Edge|2G|Dial|FIOS|Native|custom) [Cable]
- **-r, --runs** _\_: number of test runs [1]
- **-f, --first**: skip the Repeat View test
- **-v, --video**: capture video
- **-p, --private**: keep the test hidden from the test log
- **-L, --label** _\