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 🙏

© 2024 – Pkg Stats / Ryan Hefner

magic-cookie

v0.0.5

Published

Magic Cookie

Downloads

4

Readme

Magic Cookie

Supports Redis >= 2.6.12 and (Node.js >= 6).

Description

Another redis store for tough-cookie module.

Install

$ npm install magic-cookie

Basic Usage

const rp = require('request-promise');

const { MemoryCookieStore } = require('magic-cookie');

const jar = rp.jar(new MemoryCookieStore());

(async () => {
  const qs = {
    key: 'value',
    anotherkey: 'something',
    someelse: 'content',
  };

  const response = await rp('https://httpbin.org/cookies/set', { qs, jar, json: true });

  console.log(response);
})();

Import cookie from Puppeteer to Request

Use the loadPuppeteerCookie() method to import a Puppeteer cookie.

const rp = require('request-promise');
const puppeteer = require('puppeteer');
const querystring = require('querystring');

const { MemoryCookieStore } = require('./');

(async () => {
  const qs = {
    key: 'value',
    anotherkey: 'something',
    someelse: 'content',
  };
  const urlSet = `https://httpbin.org/cookies/set?${querystring.stringify(qs)}`;
  const urlGet = 'https://httpbin.org/cookies';

  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto(urlSet, { waitUntil: 'networkidle2' });

  const cookies = await page.cookies();

  await browser.close();

  const cookieMemory = new MemoryCookieStore();
  cookieMemory.loadPuppeteerCookie(cookies);

  const jar = rp.jar(cookieMemory);

  const response = await rp(urlGet, { jar, json: true });
  console.log(response);
})();

Import cookie from Request to Puppeteer

Use the loadPuppeteerCookie() method to import a Puppeteer cookie.

const rp = require('request-promise');
const puppeteer = require('puppeteer');

const { MemoryCookieStore } = require('magic-cookie');

(async () => {
  const qs = {
    key: 'value',
    anotherkey: 'something',
    someelse: 'content',
  };
  const urlSet = 'https://httpbin.org/cookies/set';
  const urlGet = 'https://httpbin.org/cookies';

  const cookieMemory = new MemoryCookieStore();

  const jar = rp.jar(cookieMemory);
  await rp(urlSet, { qs, jar, json: true });

  const cookies = cookieMemory.getPuppeteerCookie();

  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setCookie(...cookies);
  await page.goto(urlGet, { waitUntil: 'networkidle2' });
  const bodyHandle = await page.$('body');
  const response = await page.evaluate(body => JSON.parse(body.innerText), bodyHandle);

  await browser.close();
  console.log(response);
})();

Options to use with Redis Store

  • path optional You can specify which Redis address to connect. [default: 'localhost:6379 db 0']
  • id optional ID for each redis store so that we can use multiple stores with the same redis database [default: 'default']
const rp = require('request-promise');

const { RedisStore } = require('magic-cookie');

// Connect to 127.0.0.1:6380, db 4, using password "authpassword" and stores on key "my-cookie"
const jar = rp.jar(new RedisStore('redis://:[email protected]:6380/4', 'my-cookie'));

(async () => {
  const qs = {
    key: 'value',
    anotherkey: 'something',
    someelse: 'content',
  };

  const response = await rp('https://httpbin.org/cookies/set', { qs, jar, json: true });

  console.log(response);
})();