Debugging is a critical part of developing a new application — whether running code in the initial stages of development, or trying to understand an issue occurring in production. In this article, you will learn how to effectively debug your Workers application, as well as review some code samples to help you get started:
Local testing with
The command starts a local server for developing your Worker.
wrangler dev allows you to get feedback quickly while iterating by exposing logs on
localhost and to experiment without deploying to production.
wrangler dev can significantly reduce the time it takes to test and debug new features.
Local testing against remote resources
wrangler dev runs locally by default. To deploy your application to the edge preview service, and make it available for access on
wrangler dev --remote:
$ wrangler devBuilt successfully, built project size is 27 KiB.Using namespace for Workers Site "__app-workers_sites_assets_preview"Uploading site filesListening on http://localhost:8787[2020-05-28 10:42:33] GET example.com/ HTTP/1.1 200 OK[2020-05-28 10:42:35] GET example.com/static/nav-7cb303.png HTTP/1.1 200 OK[2020-05-28 10:42:36] GET example.com/sw.js HTTP/1.1 200 OK
In the output above, you can begin to see log lines for the URLs being requested locally.
Wrangler supports using the to view logs/sources, set breakpoints, and profile CPU/memory usage. With
wrangler dev running, press the d key in your terminal to open a DevTools session connected to your Worker.