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

dropbox-fetch

v0.3.2

Published

Simple Javascript wrapper for the Dropbox HTTP API, using fetch.

Downloads

12

Readme

dropbox-fetch

Simple Javascript wrapper for the Dropbox HTTP API, using fetch. This is mainly a personal project that I started because Dropbox does not provide a Javascript wrapper for their API, and most other projects that I found here on Github that do this are no longer maintained anymore or otherwise unsuitable for me.

These functions that implement the Dropbox HTTP API all are pure functions (except for the network request that is being sent, of course). They return a promise which resolves with the complete result that the API returns.

There is a convenience function setToken that allows you to set your token once and omit this in your subsequent function calls.

Requirements

You'll obviously need a Dropbox user account in order create a Dropbox app on their apps page. While this application is in development (version < 1.x), you'll need node.js version 6 to run it because I use some fancy ES6 features. I will probably support the LTS version of node.js sometime in the future.

Examples

upload

const box = require('dropbox-fetch');

const apiArgs = {
  path: '/foo/bar.txt' // this is were your file will be stored in your dropbox
  // optional parameters are omitted (see JSDoc of the upload function)
};
/* 
 * Now read the file content - you could also pass just the content as a string
 * to the upload function (if you wish to create a textfile), but I recommend
 * using a ReadStream, because it also works with images etc.
 */
const content = fs.createReadStream('foo.txt');
const token = config.token; // your personal access token

// upload the file to your dropbox
box.upload(apiArgs, content, token).then((result) => {
  // do whatever you want with the response
  console.log(result.status); // 200 (hopefully)
  // result.status could also be 400 or 500, these also result in a resolved promise
}).catch((result) => {
  console.err('something went wrong'); 
});

download

const path = '/foo/bar.txt'; // whatever file you wish to download
const token = config.token; // your personal access token

box.download(path, token).then((result) => {
  return result.text(); // promise that resolves with the file's content as a string
}).then((fileContent) => {
  // do whatever you want with the file's contents, e.g. write to a file or just log
  console.log(fileContent);
});

getMetadata


const validPath = '/tape-test/' + filename; // not neccessarily existing
const token = config.token; // your personal access token

box.getMetadata(validPath, true, true, true, token).then((result) => {
  if (result.status === 200) {
    // obtain the files metadata via result.json() (returns a promise)
    console.log('success');
  }
});

Features / Upcoming

Features:

  • upload
  • download
  • getMetadata

Upcoming:

  • authorize
  • listFiles

Contributing

You're welcome to contribute a feature to this repository. If you do, please make sure that it passes the linter (run npm run lint) and add a short unit test to test/dropbox-fetch.js (which should, obviously, pass - run the tests using npm run test).