- JavaScript 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| example | ||
| src | ||
| test | ||
| .gitignore | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
photo-feed
A small, self-hostable photo upload and feed module for Express. Point it at a folder (or later, an S3-compatible bucket), mount its router, and get multi-file uploads with EXIF-corrected thumbnails, a newest-first feed with cursor pagination, and deletes restricted to the uploader. It has no opinion about auth, accounts, or design — those are the host app's job.
Install
Requires Node 22+.
npm install photo-feed
Usage
import express from "express";
import { createPhotoFeed } from "photo-feed";
const app = express();
app.use(express.static("./data")); // serve stored files at their keys
app.use(createPhotoFeed({
storage: "local", // "local" | "s3" | a custom {put,get,delete,url,stream} object
dataDir: "./data", // images/, thumbnails/, and images.json live here
thumbWidth: 480, // max thumbnail width in px
pageSize: 24, // default and max feed page size
maxFileBytes: 25 * 1024 * 1024,
maxFiles: 20,
uploaderId: (req) => req.uploaderId, // how the host injects identity
salt: "a-long-random-secret",
}));
Routes
POST /photos— multipart upload. Fieldphotos(repeatable), optionalcontributortext field. Returns201with an array of{id, url, thumbUrl, contributor, createdAt, width, height}. Files overmaxFileBytesor uploads overmaxFilesreturn413.GET /photos— newest-first feed. Optionalcursor(opaque, fromnextCursor) andlimit(≤pageSize). Returns{photos: [...], nextCursor};nextCursorisnullat the end.DELETE /photos/:id—204when the request's uploader matches the photo's uploader,403otherwise,404when the photo doesn't exist.
Formats
Accepted upload types: JPEG, PNG, GIF, WebP, AVIF, TIFF and HEIC/HEIF.
HEIC is decoded with a WASM decoder and stored as JPEG (images/<id>.jpg) —
prebuilt sharp cannot decode HEVC — so every stored original is viewable
without extra native libraries. Thumbnails are always JPEG.
Ownership
Every photo stores sha256(uploaderId + salt). The plaintext uploader id is
never written to disk. Pass a secret salt — it makes the stored hash
unusable without it. Deleting requires the same uploaderId for that
request.
Storage backends
storage: "local" (the default) writes images/<id>.<ext> and
thumbnails/<id>.jpg under dataDir; serve that directory statically (or
through your own file route) and the url/thumbUrl fields resolve.
storage: "s3" selects an S3/Garage backend that is not implemented yet
— every operation currently throws. Configure it via the same environment
variable names used elsewhere: S3_ENDPOINT, S3_REGION, S3_BUCKET,
S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY.
Any object implementing {put, get, delete, url, stream} is accepted as a
custom backend.
Example
A runnable demo with a minimal upload form lives in example/:
node example/server.js
# open http://localhost:3000
Uploads land in example/data/images/ and example/data/thumbnails/, and
GET /photos returns the feed JSON.
Status
Early. Auth, sessions, HTML, and styling are deliberately out of scope; see the project vault for the roadmap.