leetcode-apis
v1.0.1
Published
LeetCode, CodeChef, and GeeksforGeeks API client
Maintainers
Keywords
Readme
npm install leetcode-apis
Programmatic clients and an optional HTTP server that expose a consistent REST surface for LeetCode, CodeChef and GeeksforGeeks data.
This package is useful both as an npm dependency (import the leetcode, codechef, and geeksforgeeks clients) and as a standalone server that can be run locally or in production.
Table of contents
- Installation
- Usage (package)
- Usage (server)
- API reference
- Publishing to npm
- Local testing
- Configuration
- Contributing & License
Installation
Install from npm (replace with your package name / scope):
npm install leetcode-apisOr use the repo directly for development:
Set-Location "d:\leetcode-apis"
npm installUsage (import as a package)
The package exports ready-to-use client instances from src/index.js. Example (ESM):
import { leetcode, codechef, geeksforgeeks } from 'leetcode-gfg-codechef-api';
// LeetCode example
const profile = await leetcode.getUserProfile('your_username');
console.log(profile);
// CodeChef example
const ccProfile = await codechef.scrapeUserProfile('your_username');
console.log(ccProfile);
// GeeksforGeeks example
const gfg = await geeksforgeeks.getUserProfile('your_username');
console.log(gfg);Refer to the src/controllers and src/utils files for available client methods and response shapes.
Usage (run the server)
Start the server locally (PowerShell):
Set-Location "d:\leetcode-apis"
npm run startBy default the server runs at http://localhost:3000.
Health check: GET /health
Root docs: GET / returns a JSON index of exposed endpoints and examples.
API Reference
Base mount points:
- LeetCode:
/leetcode - CodeChef:
/codechef - GeeksforGeeks:
/geeksforgeeks
LeetCode
GET /leetcode/daily— Daily challenge (processed)GET /leetcode/dailyQuestion— Raw daily questionGET /leetcode/select?titleSlug=<slug>— Problem detailsGET /leetcode/problems— Problems list (query:limit,skip,tags,difficulty)GET /leetcode/:username— User profileGET /leetcode/:username/badgesGET /leetcode/:username/solvedGET /leetcode/:username/contestGET /leetcode/:username/contest/historyGET /leetcode/:username/submissionGET /leetcode/:username/acSubmissionGET /leetcode/:username/calendarGET /leetcode/userProfile/:usernameGET /leetcode/languageStats?username=<name>GET /leetcode/skillStats/:usernameGET /leetcode/userProfileUserQuestionProgressV2/:userSlugGET /leetcode/userContestRankingInfo/:usernameGET /leetcode/user/:username/complete
Discussions (LeetCode)
GET /leetcode/trendingDiscuss?first=<n>GET /leetcode/discussTopic/:topicIdGET /leetcode/discussComments/:topicId
CodeChef
GET /codechef/user/:usernameGET /codechef/user/:username/ratingGET /codechef/user/:username/rankingGET /codechef/user/:username/statsGET /codechef/contests
GeeksforGeeks
GET /geeksforgeeks/user/:usernameGET /geeksforgeeks/user/:username/statsGET /geeksforgeeks/user/:username/solvedGET /geeksforgeeks/user/:username/practiceGET /geeksforgeeks/user/:username/contestsGET /geeksforgeeks/user/:username/schoolGET /geeksforgeeks/user/:username/completeGET /geeksforgeeks/problem-of-the-day
Examples (PowerShell)
# LeetCode daily
Invoke-RestMethod -Uri "http://localhost:3000/leetcode/daily"
# Problem details
Invoke-RestMethod -Uri "http://localhost:3000/leetcode/select?titleSlug=two-sum"
# CodeChef profile
Invoke-RestMethod -Uri "http://localhost:3000/codechef/user/some_user"
# GeeksforGeeks problem of the day
Invoke-RestMethod -Uri "http://localhost:3000/geeksforgeeks/problem-of-the-day"Publishing to npm
Before publishing, ensure package.json includes the correct fields:
name: set to the package name (scoped packages recommended, e.g.@your-scope/leetcode-gfg-codechef-api).version: follow semver.description: short package description.main/module: entry file for consumers.files: list files/folders to include in the package (minimize size).repository,license,keywords,author.
First publish (scoped package):
npm login
npm publish --access publicSubsequent publishes:
npm version patch # or minor / major
npm publishIf you publish an unscoped package you can omit --access public.
Local testing and linking
To test the package locally from another project use npm pack or npm link:
# Create tarball
cd d:\leetcode-apis
npm pack
# In test project
npm install ../d\-leetcode-apis/leetcode-gfg-codechef-api-1.0.0.tgzOr:
cd d:\leetcode-apis
npm link
# In test project
npm link leetcode-gfg-codechef-apiConfiguration & Environment
Environment variables respected by the server:
PORT— port to run the server (default3000)NODE_ENV— environment nameYOUR_DOMAIN— optional
Rate limiting is enabled via src/middleware/rateLimiter.js. Keep usage reasonable and respect upstream terms of service.
Development
- Entry:
server.jsmounts routers insrc/routes. - Exported clients:
src/index.js. - Controllers and utility clients live in
src/controllersandsrc/utils.
Contributing
Contributions and issues are welcome. Please:
- Open an issue describing the problem or feature.
- Fork the repo and send a PR with tests or a clear description of changes.
License
Add a license to package.json (MIT recommended) and include a LICENSE file in the repo.
If you'd like, I can now:
- Add an example
package.jsonconfigured for npm publishing. - Create a minimal
distbuild step andnpmprepublish script.
Which of those should I add next?
Placeholder update to match patch requirements before replacing file fully.
LeetCode, CodeChef & GeeksforGeeks Unified API
Fast, production-ready REST API to query LeetCode, CodeChef, and GeeksforGeeks data: daily problems, problem details and lists, user profiles, submissions, contests, rankings, language and skill stats, and discussion threads.
Runs on Express with security hardening (Helmet), CORS, compression, and rate limiting.
Quick Start
- Prerequisites: Node.js 18+ and PowerShell (
pwsh). - Install dependencies:
Set-Location "d:\leetcode-apis"
npm install- Start the server:
npm run start- Health check:
http://localhost:3000/health - API docs summary:
http://localhost:3000/
Configuration
- Environment variables (optional):
PORT: API port (default3000).NODE_ENV: environment label (developmentby default).YOUR_DOMAIN: used only for logging or custom setups.
Rate limiting is enabled via src/middleware/rateLimiter.js. Keep test traffic reasonable.
Base Paths
- LeetCode routes:
http://localhost:3000/leetcode/... - CodeChef routes:
http://localhost:3000/...(prefixes begin with/codechef/...) - GeeksforGeeks routes:
http://localhost:3000/...(prefixes begin with/geeksforgeeks/...)
LeetCode API Endpoints
GET /leetcode/daily: Daily challenge question (processed view).GET /leetcode/dailyQuestion: Raw daily question data.GET /leetcode/select?titleSlug=<slug>: Question details for a specific problem.GET /leetcode/problems: Problems list.- Query params:
limit,skip,tags(space or+separated),difficulty(EASY|MEDIUM|HARD).
- Query params:
GET /leetcode/:username: User profile summary.GET /leetcode/:username/badges: User badges.GET /leetcode/:username/solved: Solved count & breakdown.GET /leetcode/:username/contest: Contest participation details.GET /leetcode/:username/contest/history: Full contest history (most recent first).GET /leetcode/:username/contest/history?attendedOnly=true: Attended contests only.GET /leetcode/:username/submission: Recent submissions.GET /leetcode/:username/acSubmission: Accepted submissions only.GET /leetcode/:username/calendar: Submission calendar.GET /leetcode/userProfile/:username: Full profile in a single call.GET /leetcode/languageStats?username=<name>: Language statistics.GET /leetcode/skillStats/:username: Skill statistics.GET /leetcode/userProfileUserQuestionProgressV2/:userSlug: Question progress.GET /leetcode/userContestRankingInfo/:username: Contest ranking info.GET /leetcode/user/:username/complete: Aggregate of all user data in one call.
LeetCode Examples (PowerShell)
# Daily
Invoke-RestMethod -Uri "http://localhost:3000/leetcode/daily"
# Problem details
Invoke-RestMethod -Uri "http://localhost:3000/leetcode/select?titleSlug=two-sum"
# Problems list with filters
Invoke-RestMethod -Uri "http://localhost:3000/leetcode/problems?limit=10&tags=array+string&difficulty=EASY"
# User complete data
Invoke-RestMethod -Uri "http://localhost:3000/leetcode/user/john_doe/complete"Discussion Endpoints (LeetCode)
GET /leetcode/trendingDiscuss?first=<n>: Trending discussions.GET /leetcode/discussTopic/:topicId: Discussion topic details.GET /leetcode/discussComments/:topicId: Comments for a topic.
Discussion Examples
Invoke-RestMethod -Uri "http://localhost:3000/leetcode/trendingDiscuss?first=10"
Invoke-RestMethod -Uri "http://localhost:3000/leetcode/discussTopic/12345"
Invoke-RestMethod -Uri "http://localhost:3000/leetcode/discussComments/12345"CodeChef API Endpoints
GET /codechef/user/:username: User profile.GET /codechef/user/:username/rating: User rating (returns 0 if no contests).GET /codechef/user/:username/ranking: User ranking.GET /codechef/user/:username/stats: Complete user statistics.GET /codechef/contests: Contest list.
CodeChef Examples
Invoke-RestMethod -Uri "http://localhost:3000/codechef/user/john_doe"
Invoke-RestMethod -Uri "http://localhost:3000/codechef/user/john_doe/rating"
Invoke-RestMethod -Uri "http://localhost:3000/codechef/contests"GeeksforGeeks API Endpoints
GET /geeksforgeeks/user/:username: User profile.GET /geeksforgeeks/user/:username/stats: User statistics.GET /geeksforgeeks/user/:username/solved: Solved problems.GET /geeksforgeeks/user/:username/practice: Practice problems overview.GET /geeksforgeeks/user/:username/contests: Contest history.GET /geeksforgeeks/user/:username/school: School progress.GET /geeksforgeeks/user/:username/complete: Aggregate of all user data.GET /geeksforgeeks/problem-of-the-day: Problem of the day.
GeeksforGeeks Examples
Invoke-RestMethod -Uri "http://localhost:3000/geeksforgeeks/user/john_doe"
Invoke-RestMethod -Uri "http://localhost:3000/geeksforgeeks/problem-of-the-day"Health & Root
GET /health: Server health status and metadata.GET /: JSON index summarizing all endpoints and examples.
Error Handling
- 404: Unknown route returns structured JSON with
pathandtimestamp. - Central error middleware formats unexpected errors consistently.
Notes
- Public endpoints; no API key required.
- Respect rate limits and upstream site policies.
- Responses mirror upstream structures where applicable; fields can evolve.
Development
- Entry:
server.jsmounts routers fromsrc/routes/*. - Core clients in
src/utils/*and controllers insrc/controllers/*. - Exported SDK-like clients:
src/index.jsexportsleetcode,codechef,geeksforgeeksfor programmatic use.
License
This project is intended for personal or educational use. Do not abuse upstream services.
