Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

medium-json-feed

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

medium-json-feed

Get Medium latest articles in JSON format

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by83.33%
Maintainers
1
Weekly downloads
 
Created
Source

Medium JSON Feed

Get Medium latest articles in JSON format

Medium's public API is quite limited and it is not possible to fetch data from browsers due to CORS issue. Use this package in your server to get JSON article list from Medium or fork and deploy this minimum server to Heroku or another PaaS.

Installation

npm install medium-json-feed --save

Usage

Gets the user/publication name and an optional callback or stream. Returns a promise.

mediumJSONFeed(endpoint: string, callback?: Function | Stream): Promise

Simple example:

const mediumJSONFeed = require('medium-json-feed');

// Usernames start with '@'
mediumJSONFeed('@my-user-name')
  .then(data => ...)
  .catch(data => ...);

// Publication names without '@'
mediumJSONFeed('my-publication-name', data => ...);

// Medium's top page (trending posts)
mediumJSONFeed().then(data => ...);

Other endpoint examples are @user-name/latest, publication-name/latest or publication-name/trending.

The data response contains:

  • data.status: HTTP status code (number).
  • data.error: Error message if exists (string).
  • data.response: List of found articles (Array). The format is the one returned by Medium. Inspect data.response[...].content and data.response[...].virtuals for useful information.

To get the full raw response given by Medium, provide a stream:

// Raw stream pipe to stdout
mediumJSONFeed('@my-user-name', process.stdout);

// Raw stream pipe to server's response
mediumJSONFeed('@my-user-name', response);

Note: the raw output will likely contain random chacters at the beginning of the string that break JSON format.

For a full example, see server.js file.

Live demo (hopefully)

See The Web Tub's trending articles or Mikeal Roger's latest articles.

Deploying to Heroku

  1. Clone this repo.
  2. Create a new app in your Heroku account.
  3. Choose GitHub deploy and select your fork.
  4. Set environment variables PORT and ORIGIN (for Access-Control-Allow-Origin header).
  5. Hit 'deploy'.

Keywords

FAQs

Package last updated on 19 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc