TypeScript SDK provides access to the News API v3 from TypeScript or JavaScript
applications.
Installation
# npm
npm install newscatcher-sdk
# yarn
yarn add newscatcher-sdk
# pnpm
pnpm add newscatcher-sdk
Basic usage
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,
});
Error handling
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);
}
}
For complete documentation, including request/response types, retry
configuration, and timeouts, see the
GitHub repository.
If you use our legacy TypeScript SDK (Konfig-based), see our Legacy
SDKs documentation. We recommend
migrating to this newer SDK for improved features and ongoing support.
Resources