Frameworks
SocialCrawl with Express
Build an Express API with routes that read a profile, search many platforms and page through posts
One file, server.mjs, gets three routes, /api/profile, /api/search and /api/posts, and each answers with the API's JSON unchanged.
Prerequisites
- Node.js 22 or later.
- Express 5.
- A SocialCrawl API key. Keys start with
sc_.
Checking your account…
Set up
Install Express, then set your key in the shell.
npm install express
export SOCIALCRAWL_API_KEY=sc_your_key_hereKeep the key on the server, out of your code and out of the browser.
Get a profile
The helper sends your key in the x-api-key header and answers with the API's JSON and status.
import express from "express";
const API = "https://www.socialcrawl.dev";
const app = express();
// Send one request with your key and answer with the API's JSON and status.
// The JSON carries success, and error.type and error.doc_url when it is false.
async function socialcrawl(res, path, params) {
const answer = await fetch(`${API}${path}?${new URLSearchParams(params)}`, {
headers: { "x-api-key": process.env.SOCIALCRAWL_API_KEY },
});
res.status(answer.status).json(await answer.json());
}
app.get("/api/profile", (req, res) =>
socialcrawl(res, "/v1/tiktok/profile", { handle: req.query.handle ?? "charlidamelio" }),
);Every answer carries success. Branch on it, then on error.type, never on the message text.
Search across platforms
With dry_run=1 the search is free and runs nothing. data.estimate holds the credits and seconds the real search would take.
// dry_run=1 prices the search and runs nothing.
app.get("/api/search", (req, res) =>
socialcrawl(res, "/v1/search/everywhere", {
query: req.query.query ?? "oat milk",
format: "compact",
dry_run: "1",
}),
);Drop dry_run to run the search for 20 credits.
Get posts and the next page
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.
// Send the last answer's pagination.next_cursor back as ?cursor=.
app.get("/api/posts", (req, res) => {
const params = { handle: req.query.handle ?? "charlidamelio" };
if (req.query.cursor) params.cursor = req.query.cursor;
return socialcrawl(res, "/v1/tiktok/profile/videos", params);
});
app.listen(process.env.PORT ?? 3000);A page of posts costs 1 credit.
Test it
Start the app with node server.mjs, then call the three routes. The answers hold data.author.followers, data.estimate and pagination.next_cursor.
curl "http://localhost:3000/api/profile?handle=charlidamelio"
curl "http://localhost:3000/api/search?query=oat+milk"
curl "http://localhost:3000/api/posts?handle=charlidamelio&cursor="