File tree Expand file tree Collapse file tree 4 files changed +50
-1
lines changed
Expand file tree Collapse file tree 4 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 44 " version.ts" ,
55 " src" ,
66 " tests" ,
7- " scripts"
7+ " scripts" ,
8+ " examples/deno"
89 ],
910 "deno.inlayHints.enumMemberValues.enabled" : false ,
1011 "deno.inlayHints.functionLikeReturnTypes.enabled" : false ,
Original file line number Diff line number Diff line change 1+ API_KEY = YOUR_API_KEY
Original file line number Diff line number Diff line change 1+ # Deno basic TypeScript example
2+
3+ ## Usage
4+
5+ 1 . Setup environment variables
6+
7+ - Duplicate ` .env.example ` and name it ` .env ` .
8+ - Replace ` YOUR_API_KEY ` with your SerpApi API key.
9+
10+ 2 . Run the example
11+
12+ ```
13+ deno run example.ts
14+ ```
15+
16+ ## Notes
17+
18+ - Imports rely on ` mod.ts ` found in the root folder.
19+ - To import the published module from deno.land, update the import to the
20+ following:
21+ ``` ts
22+ import {
23+ config ,
24+ getJson ,
25+ GoogleParameters ,
26+ } from " https://deno.land/x/serpapi/mod.ts" ;
27+ ```
Original file line number Diff line number Diff line change 1+ import { loadSync } from "https://deno.land/std@0.173.0/dotenv/mod.ts" ;
2+ import { config , getJson , GoogleParameters } from "../../../mod.ts" ;
3+
4+ const { API_KEY : apiKey } = loadSync ( ) ;
5+ const params = {
6+ q : "Coffee" ,
7+ api_key : apiKey ,
8+ } satisfies GoogleParameters ;
9+
10+ // Show result as JSON (async/await)
11+ const response1 = await getJson ( "google" , params ) ;
12+ console . log ( response1 [ "organic_results" ] ) ;
13+
14+ // Show result as JSON (callback)
15+ getJson ( "google" , params , ( json ) => console . log ( json [ "organic_results" ] ) ) ;
16+
17+ // Use global config
18+ config . api_key = apiKey ;
19+ const response2 = await getJson ( "google" , { q : "Coffee" } ) ;
20+ console . log ( response2 [ "organic_results" ] ) ;
You can’t perform that action at this time.
0 commit comments