LeetCode, CodeChef, and GeeksforGeeks API client
npm install leetcode-apisleetcode, codechef, and geeksforgeeks clients) and as a standalone server that can be run locally or in production.
bash
npm install leetcode-apis
`
Or use the repo directly for development:
`powershell
Set-Location "d:\leetcode-apis"
npm install
`
Usage (import as a package)
---------------------------
The package exports ready-to-use client instances from src/index.js. Example (ESM):
`javascript
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):
`powershell
Set-Location "d:\leetcode-apis"
npm run start
`
By 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 question
- GET /leetcode/select?titleSlug= — Problem details
- GET /leetcode/problems — Problems list (query: limit, skip, tags, difficulty)
- GET /leetcode/:username — User profile
- GET /leetcode/:username/badges
- GET /leetcode/:username/solved
- GET /leetcode/:username/contest
- GET /leetcode/:username/contest/history
- GET /leetcode/:username/submission
- GET /leetcode/:username/acSubmission
- GET /leetcode/:username/calendar
- GET /leetcode/userProfile/:username
- GET /leetcode/languageStats?username=
- GET /leetcode/skillStats/:username
- GET /leetcode/userProfileUserQuestionProgressV2/:userSlug
- GET /leetcode/userContestRankingInfo/:username
- GET /leetcode/user/:username/complete
Discussions (LeetCode)
- GET /leetcode/trendingDiscuss?first=
- GET /leetcode/discussTopic/:topicId
- GET /leetcode/discussComments/:topicId
CodeChef
- GET /codechef/user/:username
- GET /codechef/user/:username/rating
- GET /codechef/user/:username/ranking
- GET /codechef/user/:username/stats
- GET /codechef/contests
GeeksforGeeks
- GET /geeksforgeeks/user/:username
- GET /geeksforgeeks/user/:username/stats
- GET /geeksforgeeks/user/:username/solved
- GET /geeksforgeeks/user/:username/practice
- GET /geeksforgeeks/user/:username/contests
- GET /geeksforgeeks/user/:username/school
- GET /geeksforgeeks/user/:username/complete
- GET /geeksforgeeks/problem-of-the-day
Examples (PowerShell)
---------------------
`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):
`bash
npm login
npm publish --access public
`
Subsequent publishes:
`bash
npm version patch # or minor / major
npm publish
`
If 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:
`bash
Create tarball
cd d:\leetcode-apis
npm pack
In test project
npm install ../d\-leetcode-apis/leetcode-gfg-codechef-api-1.0.0.tgz
`
Or:
`bash
cd d:\leetcode-apis
npm link
In test project
npm link leetcode-gfg-codechef-api
`
Configuration & Environment
---------------------------
Environment variables respected by the server:
- PORT — port to run the server (default 3000)
- NODE_ENV — environment name
- YOUR_DOMAIN — optional
Rate limiting is enabled via src/middleware/rateLimiter.js. Keep usage reasonable and respect upstream terms of service.
Development
-----------
- Entry: server.js mounts routers in src/routes.
- Exported clients: src/index.js.
- Controllers and utility clients live in src/controllers and src/utils.
Contributing
------------
Contributions and issues are welcome. Please:
1. Open an issue describing the problem or feature.
2. 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.json configured for npm publishing.
- Create a minimal dist build step and npm prepublish 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:
`powershell
Set-Location "d:\leetcode-apis"
npm install
`
- Start the server:
`powershell
npm run start
`
- Health check: http://localhost:3000/health
- API docs summary: http://localhost:3000/
Configuration
- Environment variables (optional):
- PORT: API port (default 3000).
- NODE_ENV: environment label (development by 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=: Question details for a specific problem.
- GET /leetcode/problems: Problems list.
- Query params: limit, skip, tags (space or + separated), difficulty (EASY|MEDIUM|HARD).
- 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=: 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.
$3
`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=: Trending discussions.
- GET /leetcode/discussTopic/:topicId: Discussion topic details.
- GET /leetcode/discussComments/:topicId: Comments for a topic.
$3
`powershell
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.
$3
`powershell
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.
$3
`powershell
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 path and timestamp.
- 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.js mounts routers from src/routes/*.
- Core clients in src/utils/ and controllers in src/controllers/.
- Exported SDK-like clients: src/index.js exports leetcode, codechef, geeksforgeeks` for programmatic use.