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

@aadvik-teklabs/onedrive-uploader

v1.0.2

Published

Premium OneDrive Asset Uploader with a modern drag-and-drop UI and automated OAuth2 token management.

Readme

@aadvik-teklabs/onedrive-uploader

npm version License: MIT

A production-ready Microsoft OneDrive asset uploader for Node.js. Handles OAuth2 refresh-token flow automatically (with in-memory token caching) and exposes a simple class-based API for uploading, listing, downloading, and deleting files via the Microsoft Graph API.


✨ Features

  • 🚀 Simple APIOneDriveStorage class with uploadFile, listFiles, downloadFile, deleteFile
  • 🔐 Automatic OAuth2 — refresh-token flow with cached access tokens (auto-refreshed 60s before expiry)
  • 📁 Folder support — upload to root or any folder by ID
  • 🌐 Multi-tenant — supports common or specific Azure AD tenant IDs
  • Microsoft Graph — uses the official @microsoft/microsoft-graph-client

📦 Installation

npm install @aadvik-teklabs/onedrive-uploader

🔧 Setup

1. Register an Azure AD application

  1. Go to https://portal.azure.comAzure Active DirectoryApp registrationsNew registration.
  2. Add a Web redirect URI (e.g. http://localhost:3000/callback).
  3. Under API permissions, add delegated permissions: Files.ReadWrite.All and offline_access.
  4. Under Certificates & secrets, create a Client secret.
  5. Complete the OAuth2 auth-code flow once to obtain a Refresh Token (a helper script verify-oauth.js is included in the repo).

2. Create a .env file

MS_CLIENT_ID=your-azure-app-client-id
MS_CLIENT_SECRET=your-azure-app-client-secret
MS_TENANT_ID=common
MS_REFRESH_TOKEN=your-long-lived-refresh-token

🚀 Usage

Basic upload

const { OneDriveStorage } = require('@aadvik-teklabs/onedrive-uploader');
const fs = require('fs');

const storage = new OneDriveStorage();

async function main() {
    const buffer = fs.readFileSync('./photo.jpg');
    const result = await storage.uploadFile(buffer, 'photo.jpg');
    console.log('Uploaded:', result);
}

main().catch(console.error);

Upload to a specific folder

const result = await storage.uploadFile(buffer, 'invoice.pdf', {
    folderId: '01ABCD1234EFGH5678',
});

List files

const files = await storage.listFiles('root'); // or a folder ID
console.log(files);

Download a file

const stream = await storage.downloadFile('01ABCD1234EFGH5678');

Delete a file

await storage.deleteFile('01ABCD1234EFGH5678');

Express integration example

const express = require('express');
const multer = require('multer');
const { OneDriveStorage } = require('@aadvik-teklabs/onedrive-uploader');

const app = express();
const upload = multer({ storage: multer.memoryStorage() });
const storage = new OneDriveStorage();

app.post('/upload', upload.single('file'), async (req, res) => {
    try {
        const result = await storage.uploadFile(req.file.buffer, req.file.originalname);
        res.json({ success: true, data: result });
    } catch (err) {
        res.status(500).json({ error: err.message });
    }
});

app.listen(3000);

📖 API Reference

new OneDriveStorage(config?)

Creates a new client instance. Reads credentials from environment variables (MS_CLIENT_ID, MS_CLIENT_SECRET, MS_TENANT_ID, MS_REFRESH_TOKEN).

uploadFile(buffer, fileName, options?)

  • bufferBuffer of file contents
  • fileName — target file name
  • options.folderId — optional folder ID (defaults to 'root')

listFiles(folderId)

Returns an array of files in the given folder.

downloadFile(fileId)

Returns a download stream.

deleteFile(fileId)

Deletes a file by ID.

isAvailable()

Returns true after successful authentication.


🔒 Security

  • Never commit .env to source control.
  • Rotate the MS_REFRESH_TOKEN if it may have been exposed.
  • Use least-privilege scopes on the Azure AD app.

📝 License

MIT © Aadvik Labs

🔗 Links