Package manager
Install the package from the npm registry:>=12 is required when using the package in a Node.js-based build toolchain (e.g., bundling with Vite, webpack, or esbuild). At runtime the SDK targets browser environments — it relies on the performance global and the PerformanceResourceTiming API, which are not available in a plain Node.js process.
CDN usage
You can import the SDK directly in a browser<script type="module"> without a build step using the Skypack CDN:
ES module format
The package is published as an ES module. Itspackage.json includes "type": "module" and the main entry point is:
Because the package is an ES module, you cannot use
require('@cloudflare/speedtest') in CommonJS environments. Use a bundler that handles ES module interop, or use a dynamic import() call.TypeScript support
TypeScript type definitions are bundled with the package atdist/speedtest.d.ts. No separate @types/ package is needed.
The definitions cover:
- The
SpeedTestclass and its constructorConfigOptions - All event handler signatures (
onRunningChange,onResultsChange,onFinish,onError,onPhaseChange) - The
Resultsclass and every result method - The
MeasurementConfigunion type for themeasurementsarray - The
BandwidthPointinterface returned bygetDownloadBandwidthPoints()andgetUploadBandwidthPoints()
Verify the installation
After installing, run the following to confirm the package resolves correctly:function printed to stdout.
