JavaScript and TypeScript
Install the JavaScript and TypeScript SDK, scrape a page, look up a brand, and set timeouts and retries.
The context.dev package works in JavaScript and TypeScript on Node.js 20 or later. SDKs covers the API key and the defaults all SDKs share.
Install
Scrape a page
Save this as scrape.mjs and run node scrape.mjs. It prints the page as Markdown, starting with # Example Domain.
For TypeScript, save the same code as scrape.mts, run npm install --save-dev tsx, then run npx tsx scrape.mts.
Look up a brand
Replace the request and the console.log line with this lookup. It prints the company name.
Notes
Handle insufficient credits
Catch ContextDev.APIError and inspect error_code to handle 402 USAGE_EXCEEDED:
Retry once the account has sufficient credits. Authentication refresh does not restore credits. See billing error handling.