TypeScript client library for News API
# npm npm install newscatcher-sdk # yarn yarn add newscatcher-sdk # pnpm pnpm add newscatcher-sdk
import { NewscatcherApiClient } from "newscatcher-sdk"; const client = new NewscatcherApiClient({ apiKey: "YOUR_API_KEY" }); // Search for articles await client.search.post({ q: "renewable energy", predefinedSources: ["top 50 US"], lang: ["en"], from: new Date("2024-01-01T00:00:00.000Z"), to: new Date("2024-06-30T00:00:00.000Z"), additionalDomainInfo: true, isNewsDomain: true, });
import { NewscatcherApiError } from "newscatcher-sdk"; try { await client.search.post({ q: "renewable energy", }); } catch (err) { if (err instanceof NewscatcherApiError) { console.log(err.statusCode); console.log(err.message); console.log(err.body); } }
Was this page helpful?