> Documentation index: https://www.socialcrawl.dev/llms.txt > Every page is also available as Markdown by adding .md. # Node.js (/docs/quickstart/nodejs) Read a profile, search many platforms and page through posts from Node.js with the built-in fetch Each step adds to one file, `socialcrawl.mjs`. Run it with `node socialcrawl.mjs` after each step. ## Prerequisites - Node.js 22 or later, for the built-in `fetch` and top-level `await`. - A SocialCrawl API key. Keys start with `sc_`. Get a free API key at https://www.socialcrawl.dev/dashboard/api. New accounts start with 100 welcome credits and no card is needed. ## Set your API key There is no package to install. Set your key in the shell. ```bash title="Terminal" export SOCIALCRAWL_API_KEY=sc_your_key_here ``` Keep the key on the server, out of your code and out of the browser. ## Get a profile Save this as `socialcrawl.mjs`. The `call` helper sends your key in the `x-api-key` header and stops when `success` is false. ```javascript title="socialcrawl.mjs" const API = "https://www.socialcrawl.dev"; const KEY = process.env.SOCIALCRAWL_API_KEY; // Send one request. Throw with error.type and error.doc_url when success is false. async function call(path, init = {}) { const res = await fetch(API + path, { ...init, headers: { "x-api-key": KEY, ...init.headers }, }); const body = await res.json(); if (!body.success) { const { type, message, doc_url } = body.error; throw new Error(`${type}: ${message} (${doc_url})`); } return body; } const profile = await call("/v1/tiktok/profile?handle=charlidamelio"); console.log( `followers: ${profile.data.author.followers} (credits_used ${profile.credits_used})`, ); ``` Run `node socialcrawl.mjs`. It prints the follower count from `data.author.followers` and the `credits_used` of the call. Every answer carries `success`. Branch on it, then on `error.type`, never on the message text. ## Search across platforms Add this to `socialcrawl.mjs`. With `dry_run=1` the search runs nothing and is free. `data.estimate` holds what the real search would cost and how many seconds it would take. ```javascript title="socialcrawl.mjs" const quote = await call( "/v1/search/everywhere?query=oat+milk&format=compact&dry_run=1", ); const { credits, seconds } = quote.data.estimate; console.log(`estimate: ${JSON.stringify({ credits, seconds })}`); ``` Drop `dry_run` to run the search for 20 credits. ## Get posts and the next page Add this to `socialcrawl.mjs`. Each answer holds one page of posts in `data.items`. Send `pagination.next_cursor` back as `cursor`, and stop when `pagination.has_more` is false. ```javascript title="socialcrawl.mjs" const params = new URLSearchParams({ handle: "charlidamelio" }); for (const page of [1, 2]) { const posts = await call(`/v1/tiktok/profile/videos?${params}`); const { next_cursor, has_more } = posts.pagination; console.log( `page ${page}: ${posts.data.items.length} posts (credits_used ${posts.credits_used}), next_cursor ${next_cursor}`, ); if (!has_more) break; params.set("cursor", next_cursor); } ``` A page of posts costs 1 credit. Run `node socialcrawl.mjs` again to see all three steps. ## Next steps - [Price a watch for free](/docs/engines/monitors.md): POST /v1/monitors?dry_run=1 quotes a scheduled watch of an account and creates nothing. - [Common jobs](/docs/common-jobs.md): The first call for each job, from profiles to comments and reviews. - [Search](/docs/search.md): Choose between one platform - [Errors](/docs/errors.md): Every error type, what it means, and which ones to retry.