node-amzn v1.2.1
node-amzn - Search for and get product information from Amazon
Installation
npm install node-amzn
Usage
Classes
Amazon
Amazon(tld, options)
The base Amazon class, used for searching.
tld
- The Top Level Domain for requests to use (com, ca, etc.). Useful for getting items in different currencies, or those only available in certain countries.
options
(optional) - Object, contains extra options:
proxylist
- Path to a txt file containing proxiesallowForeignProducts
- Iftrue
, will not automatically change the TLD when a link is provided for an item.
Methods
init()
- No arguments, creates request handler. Should be run before doing anything else.
find(term)
- Search Amazon for items using search term. returns array
. Calling get()
on a result will return an Item
Item
Item(Amazon, asinOrLink)
Item class, used for getting more details on an Amazon item.
Amazon
- Instance of Amazon
class.
asinOrLink
- String, product ID or product link to get details of.
Methods
get()
- Gets full details of item.
Examples
Searching for and getting information on an item
const { Amazon, Item } = require('node-amzn')
// Canadian Amazon instance
const a = new Amazon('ca').init()
// find() is async, and should be await-ed (or use .then()). Returns array of results
let catToys = await a.find('cat toy')
// Returns an Item()
let firstToy = await catToys[0].get()
console.log(firstToy.full_link)
Getting an Item() using a link or product ID (asin)
const { Amazon, Item } = require('node-amzn')
// UK Amazon instance
const a = new Amazon('co.uk', {
proxylist: 'C:/Dir/To/proxylist.txt',
allowForeignProducts: false
})
// Get information on an item with the product ID (asin) of "B07W4CK8KR"
const nintendoSwitch = await new Item(a, 'B07W4CK8KR').get()
// OR
// Get info based on link. This will automatically translate the item to the listing available
// in the country specified in the Amazon() constructor if 'allowForeignProducts' is false.
//
// In this case, it will change the amazon.com item listing to the amazon.co.uk listing.
// If 'allowForeignProducts' was true, the amazon.com listing would stay as amazon.com
const nintendoSwitch = await new Item(a, 'https://www.amazon.com/Nintendo-Switch-Neon-Blue-Joy‑/dp/B07VGRJDFY/').get()