惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
C
Check Point Blog
博客园_首页
B
Blog
D
Docker
U
Unit 42
量子位
I
InfoQ
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
GbyAI
GbyAI
L
LangChain Blog
云风的 BLOG
云风的 BLOG
博客园 - Franky
美团技术团队
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
Vercel News
Vercel News
Recent Announcements
Recent Announcements
雷峰网
雷峰网
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Google DeepMind News
Google DeepMind News

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
From Raw Text to Formatted Word Doc in Your Drive
Kashaf Abdul · 2026-05-10 · via DEV Community

Building a Serverless Notes App

I wanted a simple tool where I could paste raw text and have it automatically saved as a formatted Word document in my Google Drive – no server, no database, just a clean React app. That's how Notes to Drive was born.

The Problem

Most note taking apps are either too complex or don't give you Word documents. I wanted something minimal: type text, pick a folder, save as .docx to Drive. Simple. But building it came with some real challenges I didn't expect.

What I Used

The entire app is built with React and Vite.

For generating Word documents inside the browser, I used docx.js loaded via CDN (not npm) because the npm version is Node.js only and crashes in the browser.

To read existing .docx files for the "append" feature, I used mammoth.js, also via CDN.

Authentication and Drive access is handled entirely through Google Identity Services and the Google Drive REST API v3.

Setting Up Google Drive API

This was the trickiest part. Here's what you need to do:

Step 1: Go to Google Cloud Console and create a new project

Step 2: Enable the Google Drive API

Step 3: Set up an OAuth consent screen

Set the app to External

Add your own email as a test user (important – without this you get a 403 error)

Add the scope "drive.file" for uploading and "drive.readonly" for listing folders

Step 4: Create an OAuth 2.0 Client ID under Credentials

Set application type to Web Application

Add your localhost URL – in Vite's case that's http://localhost:5173 (not 3000, which tripped me up initially)

Step 5: Copy the Client ID and store it in a .env file as VITE_GOOGLE_CLIENT_ID

How the App Works

When a user signs in, the app uses Google Identity Services Token Client to get an OAuth access token entirely in the browser – no server callback needed.

It then:

Fetches the user's name from the Google userinfo endpoint

Loads all their Drive folders via the Drive API

The user can:

Select an existing folder from a dropdown

Type a new folder name and create it on the spot

Once a folder is selected, they type a title and their raw text, and hit save.

The Magic: Generating Word Documents

The raw text gets passed to docx.js which builds a proper Word document in memory with:

A heading

A timestamp

Each line of text as a formatted paragraph

Important: Use Packer.toBlob() – not Packer.toBuffer() or Packer.toArrayBuffer(). Both of those fail silently or throw errors in browser environments.

Uploading to Google Drive

The resulting Blob is uploaded to Google Drive using the multipart upload endpoint with FormData:

One part for the file metadata (including the parent folder ID)

One part for the actual file content

For updating existing files, the same endpoint is called with PATCH instead of POST.

The "Append to Existing" Feature

This was tricky. Here's how it works:

Download the selected .docx file from Drive

Extract its text using mammoth.js

Merge it with the new content under a new section heading

Rebuild the full document

Re-upload it to replace the original

Deployment to Netlify

Step 1: Run npm run build

Step 2: Drag the dist folder to Netlify

Step 3: Add VITE_GOOGLE_CLIENT_ID as an environment variable in site settings

Step 4: Go back to Google Cloud Console and add your Netlify URL to the Authorized JavaScript Origins of your OAuth client

Important Note: While the app is in Testing mode on Google Cloud, only emails added as test users can sign in. To make it publicly accessible, you need to publish the app to Production from the OAuth consent screen.

Common Pitfalls I Ran Into

Using localhost:3000 instead of 5173 for Vite

Forgetting to add test users – got 403 error

Using Packer.toBuffer() instead of Packer.toBlob()

Not adding the Netlify URL to Authorized JavaScript Origins

Links

GitHub

Live Demo

Written by Kashaf Abdullah

Software Engineer | MERN Stack | Web Development