This guide explains how to set up and run GhostPaste locally for development.
- Node.js 20.x or later
- npm or yarn
- Git
-
Clone the repository
git clone https://github.com/nullcoder/ghostpaste.git cd ghostpaste -
Install dependencies
npm install
-
Set up local environment variables
GhostPaste uses different environment files for different purposes:
.env- Build-time variables for local development (loaded by Next.js during build).env.production- Build-time variables for production builds (PUBLIC variables only - NO SECRETS!).dev.vars- Runtime secrets for local Wrangler development- Cloudflare Secrets - Runtime secrets for production (via
wrangler secret put)
Create these files as needed:
.env(for local build-time variables):# Public variables that are safe to expose in the client bundle NEXT_PUBLIC_TURNSTILE_SITE_KEY=1x00000000000000000000AA.dev.vars(for local runtime secrets):# Runtime secrets - these are NOT exposed to the client TURNSTILE_SECRET_KEY=1x0000000000000000000000000000000AA # Add other local development secrets here
Important: Never put secrets in
.envor.env.productionfiles as they are embedded in the client bundle during build!
For regular Next.js development without Cloudflare Workers features:
npm run devThis starts the Next.js development server at http://localhost:3000 with hot module replacement.
For development with full Cloudflare Workers features (R2, KV, etc.):
npm run previewThis command:
- Builds the app with
@opennextjs/cloudflare - Starts wrangler dev with local Miniflare v3 simulation
- Persists local state to
.wrangler/statedirectory
-
Local development (default): Uses Miniflare v3 to simulate Cloudflare services locally
npm run preview # Local simulation (no billing) -
Remote development: Connects to actual Cloudflare services
npm run preview:remote # Uses real Cloudflare resources (may incur charges)
| Script | Description |
|---|---|
npm run dev |
Start Next.js development server |
npm run build |
Build Next.js for production |
npm run preview |
Build and run with local Cloudflare simulation |
npm run preview:remote |
Build and run with remote Cloudflare resources |
npm run cf:dev |
Run wrangler dev without rebuilding |
npm run deploy |
Deploy to production |
npm run deploy:staging |
Deploy to staging environment |
npm run test |
Run tests |
npm run lint |
Run ESLint |
npm run typecheck |
Run TypeScript type checking |
npm run cf:typegen |
Generate TypeScript types for Cloudflare bindings |
npm run cf:tail |
Tail production logs |
When using npm run preview, the following services are simulated locally:
- Local R2 bucket simulation for file storage
- Data persisted in
.wrangler/state/r2 - No AWS S3 API calls or charges
- Local KV namespace simulation
- Data persisted in
.wrangler/state/kv - No Cloudflare KV API calls or charges
- Build-time variables (NEXTPUBLIC*) loaded from
.envduring build - Runtime environment uses
env.developmentfromwrangler.toml - Runtime secrets loaded from
.dev.varsfile ENVIRONMENT=developmentandNEXT_PUBLIC_APP_URL=http://localhost:3000
During local development, all console logs are visible in the terminal.
Check the .wrangler/state directory to inspect:
- R2 bucket contents
- KV namespace data
- Cache contents
Generate types for Cloudflare bindings:
npm run cf:typegenThis updates worker-configuration.d.ts with the latest binding types.
If port 8787 is already in use:
# Find the process using the port
lsof -i :8787
# Kill the process
kill -9 <PID>If you encounter build errors:
- Delete
.nextand.open-nextdirectories - Run
npm run cf:buildagain
Ensure the R2 binding is correctly configured in wrangler.toml:
[[r2_buckets]]
binding = "GHOSTPASTE_BUCKET"
bucket_name = "ghostpaste-bucket"The Cloudflare Workers preview doesn't support hot reload. You need to:
- Make your changes
- Stop the dev server (Ctrl+C)
- Run
npm run previewagain
For faster development of UI components, use npm run dev for Next.js hot reload, then test with npm run preview when you need Workers features.
- Use local development (
npm run preview) for most development to avoid API charges - Persist state with
--persist-toflag to maintain data between restarts - Clear state by deleting
.wrangler/statewhen you need a fresh start - Use remote development (
npm run preview:remote) only when testing with production-like data
- Check out the Architecture Guide to understand the system design
- Review Security Guidelines for encryption implementation
- See Contributing Guide for code standards and development workflow