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 🙏

© 2026 – Pkg Stats / Ryan Hefner

traktapi2

v1.4.0

Published

A Trakt.tv API wrapper for their new APIv2

Readme

TraktApi2

A promise style Trakt.tv API wrapper for Node.js.

Example usage

Initialize

var Trakt = require('traktapi2');
var trakt = new Trakt({
  client_id: '',
  client_secret: '',
  redirect_uri: null // Defaults to urn:ietf:wg:oauth:2.0:oob,
  user_agent: 'TraktClientNr1', // Defaults to url for this repository
  endpoint: 'http://staging.api.trakt.tv' // Defaults to https://api-v2launch.trakt.tv
});

Generate Auth URL

var url = trakt.authUrl();

Authorize device

trakt
  .authorizeDevice(function(code) {
    /*
     * {
     *   user_code: 'Display this code to the user',
     *   verification_url: 'https://trakt.tv/activate',
     * }
     */
  })
  .then(function(result) {
    /* Result is true if the user allowed and false if the user explicitly denied. */
  })
  .catch(function(error) {
    /* Detailed error with failure reason.
     * You will probably want to try again.
     */
  });

Verify code/PIN (and optionally state) from returned auth

trakt
  .authorizeCode("code/PIN", "csrf token (state)")
  .catch(function(err) {
    /* Detailed error with reason of failure. */
  })
  .then(function() {
    /* API can now be used with authorized requests */
  });

Check if token needs to be refreshed

var update = trakt.isTokenExpired() ? 'yes' : 'no';

Refresh token

trakt
  .refreshToken()
  .catch(function(err) {
    /* Detailed error with reason of failure. */
  })
  .then(function() {
    /* API now has an updated access token */
  });

Storing token over sessions

var tokenObj = trakt.serializeToken(); // get token
/* Do storage and reloading etc here */
trakt.setAccessToken(tokenObj); // restore token

Actual API requests

To see a list of methods and code path to each Trakt endpoint check out the method map.

The parameter extended is available everywhere. But really only useful where media objects are returned.

trakt
  .calendars.all.shows({
    start_date: "today",
    days: "7",
    extended: "images"
  })
  .catch(function(err) {
    /*
     * Return error is either a string with a simple message, or an
     * object with details as provided by error source.
     * These objects usually looks like this:
     * {
     *   error: // Either a string with a trakt error, or the status code returned.
     *   error_description // A string describing the error
     *   original_error // Original error item from source
     *   response // response object provided by got
     * }
     */
  })
  .then(function(shows) {
    /*
     * shows now contain body response from API (actual show data).
     * If API endpoint supports pagination, an additional pagination object
     * is added to the object.
     * pagination: {
     *   page: 0, // Current page
     *   limit: 10, // Current limit (items per page)
     *   page-count: 100, // Amount of pages with the current settings
     *   item-count: 1000, // Amount of actual items.
     * }
     */
  });

Contributing

Feel free to do pull requests, forks or anything really. If you find an error and don't want to fix it yourself, place an issue and I will look into it!

LICENSE

The MIT License (MIT)

Copyright (c) 2015 Patrick Engström

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.