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

unofficial-amazon-search

v2.0.8

Published

A simple client for searching Amazon

Downloads

52

Readme

unofficial-amazon-search

A simple client for searching Amazon

Install

npm install unofficial-amazon-search

or

yarn add unofficial-amazon-search

How to use

searchAmazon returns Promise<SearchData>.

import {searchAmazon, AmazonSearchResult} from 'unofficial-amazon-search';
// OR
const {searchAmazon, AmazonSearchResult} = require('unofficial-amazon-search');

searchAmazon('anything you would put in the search bar').then(data => {
  console.log(data);
  console.log(data.pageNumber)    // 1
  console.log(data.searchResults[0].title, data.searchResults[0].imageUrl);
});

// load other pages by specifying a page number
// or calling getNextPage()
searchAmazon('mad max', {page: 2, includeSponsoredResults: true}).then(data => {
  console.log(data.pageNumber)    // 2
  console.log(data.searchResults) // (page 2 results)
  return data.getNextPage();
}).then(data => {
  console.log(data.searchResults) // (page 3 results)
});

The above works in Node and frontend environments with compiled code.

unofficial-amazon-search can also be imported from a <script> tag and used in raw JS. Importing it will attach the module to the window object. Browser queries are proxied through AllOrigins.win, a limit-free proxy, to avoid CORS issues.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>My beautiful webpage</title>
  <meta charset="UTF-8">
</head>
<body></body>
<script src="path/to/unofficial-amazon-search/_bundles/unofficial-amazon-search.min.js" rel="script"></script>
<script>
  var searchAmazon = window.UnofficialAmazonSearch.searchAmazon;
  searchAmazon('123').then(function (data) {
    console.log(data.searchResults);
  });
</script>
</html>

The bundle contains minified and non-minified bundles of the compiled search code.

This is a Promise-based API and does not support callbacks, so you will have to roll your own solution for Internet Explorer.

API

Function searchAmazon

Parameters:

  • query - string that you'd put into the Amazon website search bar
  • config - optional object, can specify any (or none) of the properties on SearchConfig.

Returns a Promise<SearchData>.

Interface SearchConfig

  • page - desired page of results
  • includeSponsoredResults - set true to include ads

Interface SearchData

An object with properties:

  • searchResults - Array<AmazonSearchResult>
  • pageNumber - Page number of current set of searchResults
  • getNextPage - If there is another page of results for the given query, this function returns a Promise for that next page. If there is no next page, this is undefined.

Class AmazonSearchResult

A diagram of an Amazon search result annotated by property (includes price labels)

A diagram of an Amazon search ad annotated by property (no price labels)

  1. imageUrl - lead product image that shows in search results
  2. title - name of product
    productUrl - URL for product details page
  3. rating - x out of y possible score (e.x. 4.2 out of 5)
  4. prices - Search often lists multiple prices for versions of an item. This is a set of all found prices, some of which have labels attached (for example, if you search a DVD barcode number, there are multiple prices, for DVD, Blu-ray and 4K, and each has a label like "4K"). Price label is null if cannot find it on page
  5. sponsored - whether result is an ad. searchAmazon filters out these by default