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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cdnetworks

v1.0.3

Published

A simple Node.js wrapper for the CDNetworks Cache Flush Open API v2.4.0

Readme

cdnetworks

A simple Node.js wrapper for the CDNetworks Cache Flush Open API v2.4.0


Table of contents


Installation

npm install cdnetworks


Create an instance

var cdn=require('cdnetworks')(); will create an instance with default values

Either override the defaults on instantiation

var cdn=require('cdnetworks')({user:'[email protected]',pass:'secret'})

or later on, at any time with cdn.setValues(conf), which returns the cdn instance. So a method can be chained

cdn.setValues(conf).padList()

Defaults

{
    user: null,
    pass: null,
    output: 'json', // xml not supported
    type:'item', // (doPurge): item || wildcard || all
    mailTo: [''], // (status): array of emails to receive flush notifications
    servicearea: 'US',
    openStatusPage:false // (status): open flush status page in browser
}

Return types

setValues returns the cdn instance.

The actual API methods return a promise.

You would normally follow the method call with a then/catch

cdn.padList()
.then(function(res){
    // cool. do something with res
})
.catch(function(err){
    // bad. handle err
})

API

padList

Lists all the PADs (domains) available to the user

Required arguments: [user, pass]

Optional: [output]

example
cdn.padList()
.then(function(pads){
    console.log(pads)
})
response
[
 'image.foocdn.com',
 'adv.foocdn.com'
]

doPurge

Sends cache flush requests.

Required arguments: [user, pass, type, pad],

Optional: [path, output]

Available types are ['item','wildcard','all']

Default is item.

all doesn't require path, because all items will be flushed.

example

This sends item flush for 2 files (assuming type has't been overridden)

cdn.doPurge({
    pad: 'image.foocdn.com',
    path: [
        '/imgs/cutepuppy.jpg',
        '/img/littlekitten.jpg'
    ]
})

This sends wildcard flush for n files in that directory

cdn.doPurge({
    type: 'wildcard',
    pad: 'image.foocdn.com',
    path: ['/imgs/cutepuppies/*']
})

This sends wildcard flush, overriding type on the cdn instance, which will also apply to following calls

cdn.setValues({ type: 'wildcard' }).doPurge({
    pad: 'image.foocdn.com',
    path: ['/imgs/cutepuppies/*']
})
.then(function(res){
    console.log(res)
})
response
{
 'resultCode':200,
 'pid': 13459,
 'details': 'success (2 items)',
 'paths':[
    '/images/logo.gif',
    '/images/copyright.gif'
 ],
 'notice': 'Maintenance scheduled at ...'
}

On each succesful purge the PID (purge id) is stored on the instance, and used by cdn.status() if no PID is provided

status

Check Flush Completion Status

Required arguments: [user, pass, pid]

Optional: [ output, mailTo, openStatusPage]

example

this uses the last stored PID from latest flush

cdn.status()

this overddides some defaults and queries a PID that might not be from the latest purge

cdn.setValues({
    emailTo:[
        '[email protected]',
        '[email protected]'
    ],
    openStatusPage:true
}).status(12345)
response
{
    "details": "Requested information returned",
    "percentComplete": 100,
    "resultCode": 200
}

That being said, in my tests status() will almost invariably return a 400 if called right after a purge. That is because the PID takes about 10-15 seconds to be ready for queries. Optionally one can set openStatusPage:true to have the status page open in a browser. One can then refresh the page to check the status.


Service area

CDNetworks offers different access domains for different areas served.

Available service areas are

{
    US: 'https://openapi.us.cdnetworks.com/purge/rest/',
    KR: 'https://openapi.kr.cdnetworks.com/purge/rest/',
    JP: 'https://openapi.jp.cdnetworks.com/purge/rest/',
    CN: 'https://openapi.txnetworks.cn/purge/rest/'
}

The default is US/Global. I haven't noticed any difference using one or the other, but there you have them.

Again, you can override the default service area either on instantiation or later on with, for instance, setValues({servicearea:'JP'})


Example usage

var cdn=require('cdnetworks')({
    user:'[email protected]',
    pass:'secret',
    emailTo:['[email protected]']
});

var pidArr = [];

cdn.doPurge({
    type: 'wildcard',
    pad: 'that.domain.com',
    path: ['/some/path/*']
})
.then(function (res) {
    pidArr.push(res.pid);
    console.log(res);
    return cdn.doPurge({
        pad: 'that.otherdomain.com',
        path: ['/stuff/to/purge.js']
    })
})
.then(function (res) {
    pidArr.push(res.pid);
    console.log(res);
    cdn.setValues({ openStatusPage: true });
    pidArr.forEach(function (idx, pid) {
        cdn.status(pid);
    });
})
.catch(function (err) {
    console.log(err)
})

Additional notes

Although the CDNetworks API offers both XML and JSON as output types, only JSON is supported here. I can't see why anyone would want to have to deal with XML rather than JSON when working with JavaScript. I would certainly avoid it when possible, so I did.

Please see the CDNetworks API documentation for a full list of options and parameters for each API call