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

gtrendsjs

v1.0.0

Published

non-official api to google trending stories

Downloads

9

Readme

gTrendsjs

is a non-official api wrapper to get latest trending news filterd by categories and countries, it is a sample and basic class which comsume multilple endpoints, the project started as basic a copied curl calls from the google trends webapp, then turned into this class, the library uses xml2json and got as dependecies to accomplish the goal.

it doesn't uses any cache system you will have to think about implementing cache for actual use.

Features

  • Get trending stories on google search by country and by category.
  • Get single story details (timeline & other data )
  • Fast and reliable – it uses the same servers that trends.google.com uses

Change Log

How to install the library ?

To install the library just type in

npm install gtrendsjs

or if you use yarn

yarn add gtrendsjs

then require or import it in your javascript file

Usage

take look at example.js and supported params

  • getting trending news

const Gtrends = require('gtrends');

// accepts three params geo, category and lang
// geo supports one of these strings 'FR', 'EG', 'HK', 'IL', 'SA', 'TW', 'TH', 'TR', 'UK', 'US', 'VT'
// for the category 'all, business, entertainment, health, sicTech, sports, top'
const news = new Gtrends('US', 'all');
const latest = await news.getHourlyGrends()

the response is format

Array of trending news stories as objects, each object contain also an array of similar story and other data

[
  {
    "id": 0,
    "storyId": "US_lnk_fG_QSwEwAACtlM_en",
    "title": "Trending story title .... ",
    "link": "full link to the google trends story .... https://trends.google.com/",
    "imgUrl": "static img url provided",
    "imgSrc": "IMAGE SOURCE(PUBLISHER NAME)",
    "imgPost": "LINK TO IMAGE POST ARTICLE ",
    "tags": [
      "ARRAY OF TAGS TAG1",
      "TAG2", "TAG3"
    ],
    "stories": [
      {
        "id": 0,
        "title": "FIRST STORY TITLE ",
        "snippet": "STORY EXCERPT",
        "source": "SOURCE PUBLISHER NAME",
        "time": "52 minutes ago",
        "url": "FULL URL TO POST STORY"
      },
    ]
  },
  ... 
]
  • getting single story
const singleStory = new Grends("US", "category");
const storyData = await singleStory.getSingleStory("US_lnk_fG_QSwEwAACtlM_en");

supports params

const CATEGORIES = {
  all: "all",
  business: "b",
  entertainment: "e",
  health: "h",
  sicTech: "t",
  sports: "s",
  top: "t",
}

const COUNTRIES = ['FR', 'EG', 'HK', 'IL', 'SA', 'TW', 'TH', 'TR', 'UK', 'US', 'VT'];

testing

the code is not well tested, but a basic test is written to verify if is library is getting the right data, to develop upon it in the future maybe !