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-onedrive-unofficial

v0.0.6

Published

An unofficial node.js client for OneDrive

Downloads

5

Readme

node-onedrive-unofficial v0.0.6

node-onedrive-unofficial is a limited OneDrive client using the new OneDrive API.

What works:

  • authentication
  • uploading a single file using the chunked uploader
  • raw API calls

What doesn't work yet:

  • convenience methods for everything else
  • Passport integration for OAuth2 (currently manual)
  • self-hosted authentication server

Getting started

  1. Install Node.js (includes npm)

    Note to Windows users installing Node.js for the first time: You may need to sign out of your Windows account for your PATH changes to take effect.

  2. Install node-onedrive-unofficial using npm

    npm -g install node-onedrive-unofficial

  3. Get a one-time sign-in code for your Microsoft account here: https://seattle.gregedmiston.com/scratch/onedrive-auth

    Want to use your own app ID and sign-in page for redistribution? See "Advanced authentication" section near the bottom.

  4. Redeem your sign-in code using onedrive.js

    • If you installed globally using npm -g, then run:

      onedrive signin YOURCODEHERE

    • If you installed the package locally or don't have your PATH configured for npm, you can run it locally:

      node ./node-modules/node-onedrive-unofficial/onedrive.js signin YOURCODEHERE

  5. Try it out using the command line first.

    For help:

    onedrive --help

    Get a folder listing of your OneDrive:

    onedrive api /drive/root/children

###Using the command line

Upload ./localfolder/foo.txt to /destination.txt

onedrive put ./localfolder/foo.txt /destination.txt

Get a folder listing of your OneDrive:

onedrive api /drive/root/children

Delete file /filetodelete.txt

onedrive api --method=DELETE /drive/root:/filetodelete.txt

Rename /oldname.txt to /newname.txt:

onedrive api --method=PATCH /drive/root:/oldname.txt --body='{"name": "newname.txt"}

See the full list of OneDrive APIs.

Using the npm package in node.js

Include the package

var onedrive = require('node-onedrive-unofficial');
var account = null; // use built-in easy authentication

The examples below use the built-in app ID. These assume that you have already signed in using the command line signin command described in Getting started.

Upload ./localfolder/foo.txt to /destination.txt

onedrive.put( account, './localfolder/foo.txt', '/destination.txt', function(uploadedItem, err) {
  if (!err) {
  	// do something with uploadedItem
  }
});

Get a folder listing of your OneDrive:

onedrive.api( account, {
  path: '/drive/root/children'
}, function(folderListing, err) {
  if (!err) {
    // do something with folderListing
  }
});

Rename /oldname.txt to /newname.txt

onedrive.api( account, {
  path: '/drive/root:/oldname.txt',
  method: 'PATCH',
  body: {"name": "newname.txt"}
}, function(response, err) {
  if (!err) {
    // success
  }
});

Delete file /filetodelete.txt

onedrive.api( account, {
  path: '/drive/root:/filetodelete.txt',
  method: 'DELETE'
}, function(response, err) {
  if (!err) {
    // success
  }
});

Advanced authentication

Developer IDs

There are 2 options for developer IDs:

  1. Use the default developer ID. Requires authenticating using my janky website. The default developer config is provided in the microsoft-developer-config.json file in the npm package.
    • command line: No arguments are necessary.
    • node: Passing null for the first argument will use the default developer config.
  2. Make your own developer ID and OAuth2 callback website. Read more in the OneDrive API docs. You can sign up for a Microsoft developer ID.
    • You will need to store your clientId, clientSecret, and redirectUri in a JSON object.
    • command line: Save a file with your developer config JSON. Provide that JSON file with --config=myDevConfig.json during any call.
    • node: Pass the developer config JSON object as the first parameter to any of the OneDrive methods.

Token storage

There are 2 options for storing user tokens:

  1. Use the default user token storage. After signin, tokens are stored as .microsoft-user-tokens.json in your user's home folder. By default, tokens are automatically read from this path and written with updated tokens.
    • command line: No arguments are necessary.
    • node: Passing null for the first argument will use the default token storage.
  2. Provide your own token storage.
    • command line: Provide --token myTokenFile.json with every call.
    • node: Pass the developer config JSON object (see section above) as the first parameter to any of the OneDrive methods. You should append a lastAuthTokens section to the config. With every response, you will get an updated token.