Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including youtube-comments-task with all npm packages installed. Try it out:

var youtubeCommentsTask = require("youtube-comments-task")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

youtube-comments-task v1.3.14

Scrape comments from YouTube Videos.


Scrape comments, including their replies, from a YouTube video.

Build Status



npm install --save youtube-comments-task


The module exports a single function:


The function accepts the YouTube videoId and an optional pageToken, and returns a Task that resolves to the corresponding page of comments. If the pageToken is not provided it fetches the first page of comments.

The result is an object with the following properties.

  comments: [ { comment }, { comment }, ... ],
  nextPageToken: 'nextpagetokenhere'

Note: If the fetched page is the last page, the result does not contain the nextPageToken property.

Comment Data

  id: {{ comment id}},
  author: {{ comment author name }},
  authorLink: {{ comment author link (channel) }},
  authorThumb: {{ comment author avatar thumb url }},
  text: {{ comment text }},
  likes: {{ comment up-votes }},
  time: {{ how long ago the comment was posted (relative, e.g. '1 year ago') }},
  timestamp: {{ timestamp when comment was posted in milliseconds (absolute, e.g. 1457661439642 }},
  edited: {{ whether the comment was edited by the authro (true/false) }},
  hasReplies: {{ whether the comment has replies (true/fasle) }},
  repliesToken: {{ token used to fetch replies for the comment }},
  numReplies: {{ number of replies }},
  replies: [ {{ reply objects (same fields as comments) }} ]


Errors are as descriptive and (hopefully) useful as possible. Private, deleted, and unavailable videos are detected, and an appropriate error type is assigned. Error types are defined in /src/lib/error-types.js.

A typical error object has the following fields.

  type: {{ error type }},
  message: {{ error message }},
  videoId: {{ YouTube video id }},
  component: {{ module component }},
  operation: {{ operation that failed }}


The module uses Folktale's Task monad (data.task) to handle asynchronicity and to allow for easy composition.

If you'd rather use Promises instead of Tasks, check out youtube-comment-api.


The module is transpiled with Babel and is compatible with node.js versions >= 6.


const fetchComments = require('youtube-comments-task')

  .fork(e => console.error('ERROR', e),
        p => {
          console.log('comments', p.comments)
          console.log('nextPageToken', p.nextPageToken)
const Task = require('data.task')
const fetchComments = require('youtube-comments-task')

const fetchAllComments = (videoId, pageToken, fetched = []) =>
  fetchComments(videoId, pageToken)
    .chain(({ comments, nextPageToken }) =>
        ? fetchAllComments(videoId, nextPageToken, fetched.concat(comments))
        : Task.of(fetched.concat(comments)))

  .fork(e => console.error('ERROR', e),
        allComments => console.log(allComments))

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free