npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@codingsnack/leetcode-api

v0.0.6

Published

leetcode api

Downloads

90

Readme

Table of Contents

Introduction

This is a npm library through which one can interface with leetcode api.

Getting Started

Install the api into your node project through npm or yarn.

  • npm: npm i @codingsnack/leetcode-api
  • yarn: yarn add @codingsnack/leetcode-api

Example Usage

To use this api, you need to login to your leetcode.com account and then copy the two cookies mentioned below and pass it to Leetcode constructor. You can get these cookies using chrome devtools or EditThisCookie chrome extension.

  • csrfToken
  • LEETCODE_SESSION
const { Leetcode } = require('@codingsnack/leetcode-api');

const main = async () => {
  // csrfToken after you've logged in
  const csrfToken = '';
  // LEETCODE_SESSION after you've logged in
  const session = '';

  const lc = new Leetcode({ csrfToken, session });

  const problem = await lc.getProblem('two-sum');
  console.log(problem);

};

main();

Available methods

Currently availably methods are

  • getProblem(slug): Get information about single problem based on its title(also referred to as slug)
  • getMyLists(): Get all the lists that you have created or have favorited.
  • getProblems(params): Get all the problems based on passed params. Supports pagination, filter by category, listId, difficulty, status, premiumOnly, tags, companies, searchKeyWords. You can also orderBy FRONTEND_ID, AC_RATE(acceptance rate), DIFFICULTY, FREQUENCY. Sort order can be ascending or descending. This is same as going to https://leetcode.com/problems.
  • getSubmission(slug): Get all submissions for given problem.
  • getRandomQuestion(): Get a random question.
  • getPublicList(listId): Get a public list based on its listId.
  • getProblemsByTag(tag): Get problems by tag(like array). This is same as going to https://leetcode.com/tag/array.
  • getProblemsByCompany(company): Get problems by company(like apple). This is same as going to https://leetcode.com/company/apple.
  • getSimilarProblems(slug, depth = 1): Get similar problems based on slug. Depth param is optional and default value is 1. If depth is say 2 and slug is two-sum, then this will fetch similar questions to two-sum and then similar questions to all the similar questions of two-sum. Note that this will return a problem instance and this will have a field called similarProblems which is an array and the consumer can recurse through this. Also note that this method is still in beta.
  • addQuestionToFavorite(favoriteSlug, questionSlug): Add a question to a favorite list. Returns an object with ok (boolean) and error (string) properties.
  • batchAddQuestionsToFavorite(favoriteSlug, questionSlugs): Add multiple questions to a favorite list. Returns an object with ok (boolean) and error (string) properties.

Docs

For docs refer this link.

Todo

Features

  • Post submission and get the result back
  • Fetch any user profile(including contribution graph)
  • Fetch loggedIn user's session details(as in progress mainted by leetcode).
  • Fetch discuss sections for a problem
  • Optimize similarProblems method
  • Build adjaceny list of problems based on tag, company etc so its easier to visualize the connections between similar problems.

Technical/Other Improvements

  • Add better docs, wiki and examples.
  • Add Contributing Page.
  • Add github actions to check the build process and automatically generate docs and deploy them.
  • Update master branch to main branch.