1.3.0 • Public • Published



    A simple interface around the Marvel Comics API. Suited for Node and the Browser.

    demo - source


    The existing modules (marvel, marvel-api) are a bit over-engineered and also 300-400kb after compression. This one has a simpler interface, uses xhr in the browser, and bundles to roughly 13kb.


    npm install marvel-comics-api --save


    var api = require('marvel-comics-api')
    // fetch 50 Marvel characters
    api('characters', {
      publicKey: '.. your public key ..',
      privateKey: '.. your private key ..',
      timeout: 4000,
      query: {
        limit: 50
    }, function (err, body) {
      if (err) throw err
      // total # of items
      // array of characters

    In the browser, and once you've set up referrers, the privateKey field is not needed.

    Consult the API documentation for details on the JSON response.



    req = marvelApi(api, opt, cb)

    Requests the given api string, like 'characters' or '{characterId}/stories'.


    • publicKey (string)
      • required - your public API key
    • privateKey (string)
      • optional - your private API key, see Private Key for details
    • query (object)
      • query parameters given to the request, such as limit or 'nameStartsWith'
    • timeout (number)
      • number of milliseconds before timeout; default 0 (no timeout)
    • headers (object)
      • optional headers to pass along with the request

    Other parameters will be sent to got (node) and xhr.

    The cb is called with (err, body, response) where err will be null/undefined if the request succeeds, body will be a parsed JSON object from the request, and response will be the response headers from the XHR/HTTP request.


    Aborts the request early, sending an error to the callback.

    Private Key

    The privateKey is necessary for server-side use.

    In the browser, if you've set up authorized referrers in your Marvel Developer Account, you can ignore the privateKey field. This way you can avoid publishing your private key in the final JavaScript bundle.

    However, it can still be useful to use privateKey in the browser for quick prototyping and a unified code path.

    Building from Source

    If you want to run the unit tests and demo from source:

    git clone
    cd marvel-comics-api
    npm install

    running the demo

    You can run the demo without a Marvel Developer account.

    npm run start

    Now open in your browser to see the result.

    running tests

    You will need a Marvel Developer account to run the tests. Once you have API keys, you will need to change the test/key-public.json to a string with your public API. Then you will need to add a new file, test/key-private.json with a string containing your private key, like this:


    After that, you should be able to run the tests in Node/browser:

    npm test

    Using your own Marvel Account, the browser demo will only work locally once you've authorized (your local IP) as a referrer.

    See Also


    MIT, see for details.


    npm i marvel-comics-api

    DownloadsWeekly Downloads






    Last publish


    • mattdesl