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

node-aria2

v1.1.0

Published

Aria2 RPC client for Node.js

Downloads

30

Readme

node-aria2

Aria2 RPC client for Node.js 🌍

Features

  • Typescript support ✅
  • Promise based API 🎁
  • Support most of aria2 methods 🎉
  • Up to date with latest aria2 version (1.35.0) ✨

Setup

🚀 Run aria2 with the following command

aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all

This will start aria2 with RPC enabled on port 6800 by default, if you want to change the port, you can do so by adding --rpc-listen-port=PORT to the command. Run aria2c --help to see all the options 🎩

📦 Install node-aria2 with your favorite package manager

# npm
npm install node-aria2

# yarn
yarn add node-aria2

# pnpm
pnpm add node-aria2

📡 Usage

Default options:

{
  host: 'localhost',
  port: 6800,
  secure: false,
  secret: '',
  path: '/jsonrpc',
}

secret is optional and refers to --rpc-secret. If you define it, it will be added to every call for you!

If the WebSocket is open aria2.js will use the WebSocket transport, otherwise the HTTP transport.

The "aria2." prefix can be omitted from both methods and notifications.

📍open

aria2.open() opens the WebSocket connection. All subsequent requests will use the WebSocket transport instead of HTTP.

aria2
    .open()
    .then(() => console.log('open'))
    .catch((err) => console.log('error', err))

📍close

aria2.close() closes the WebSocket connection. All subsequent requests will use the HTTP transport instead of WebSocket.

aria2
    .close()
    .then(() => console.log('closed'))
    .catch((err) => console.log('error', err))

📍call

aria2.call() calls a method. Parameters are provided as arguments.

Example using addUri method to download from a magnet link.

const magnet =
    'magnet:?xt=urn:btih:88594AAACBDE40EF3E2510C47374EC0AA396C08E&dn=bbb_sunflower_1080p_30fps_normal.mp4&tr=udp%3a%2f%2ftracker.openbittorrent.com%3a80%2fannounce&tr=udp%3a%2f%2ftracker.publicbt.com%3a80%2fannounce&ws=http%3a%2f%2fdistribution.bbb3d.renderfarming.net%2fvideo%2fmp4%2fbbb_sunflower_1080p_30fps_normal.mp4'
const [guid] = await aria2.call('addUri', [magnet], { dir: '/tmp' })

📍multicall

aria2.multicall() is a helper for system.multicall. It returns an array of results or throw if any of the call failed.

const multicall = [
    [methodA, param1, param2],
    [methodB, param1, param2]
]

const results = await aria2.multicall(multicall)

📍batch

aria2.batch() is a helper for batch. It behaves the same as multicall except it returns an array of promises which gives more flexibility in handling errors.

const batch = [
    [methodA, param1, param2],
    [methodB, param1, param2]
]

const promises = await aria2.batch(batch)

📍listNotifications

aria2.listNotifications() is a helper for system.listNotifications. The difference with aria2.call('listNotifications') is that it removes the "aria2." prefix from the results.

const notifications = await aria2.listNotifications()
/*
[
  'onDownloadStart',
  'onDownloadPause',
  'onDownloadStop',
  'onDownloadComplete',
  'onDownloadError',
  'onBtDownloadComplete'
]
*/

// notifications logger example
notifications.forEach((notification) => {
    aria2.on(notification, (params) => {
        console.log('aria2', notification, params)
    })
})

📍listMethods

aria2.listMethods() is a helper for system.listMethods. The difference with aria2.call('listMethods') is that it removes the "aria2." prefix for the results.

const methods = await aria2.listMethods()
/*
[ 'addUri',
  [...]
  'system.listNotifications' ]

*/

📍events

// emitted when the WebSocket is open.
aria2.on('open', () => {
    console.log('aria2 OPEN')
})

// emitted when the WebSocket is closed.
aria2.on('close', () => {
    console.log('aria2 CLOSE')
})

// emitted for every message sent.
aria2.on('output', (m) => {
    console.log('aria2 OUT', m)
})

// emitted for every message received.
aria2.on('input', (m) => {
    console.log('aria2 IN', m)
})

Additionally every aria2 notifications received will be emitted as an event (with and without the "aria2." prefix). Only available when using WebSocket.

aria2.on('onDownloadStart', ([guid]) => {
    console.log('aria2 onDownloadStart', guid)
})