Getting Started

Last updated


This page starts node-image-server with Docker Compose and walks through the first upload and fetch.

Prerequisites


ItemVersion
Docker and Docker Compose v2Recommended deployment
Node.js22 or higher (only for running on the host; the container uses node:22-alpine)

Start with Docker Compose


  1. git clone https://github.com/pardnio/node-image-server.git
  2. cd node-image-server
  3. docker compose up -d

ServiceImageRole
nginxnginx:stable-alpineListens on 8080, loads config/nginx/nodejs.conf
nodejsnode:22-alpineRuns npm install on start, then loads app.ts with npx pm2-runtime start app.json

Express listens on NODE_PORT (8080 in app/.env). In the shipped config/nginx/nodejs.conf, only /c/img/ proxies to nodejs:8080; the /upload/, /del/, and / blocks proxy to nodejs:3000. Point those three blocks at the same port before the first upload, then restart Nginx:
  1. sed -i.bak 's#http://nodejs:3000#http://nodejs:8080#' config/nginx/nodejs.conf
  2. docker compose restart nginx

Run on the Host


  1. cd node-image-server/app
  2. npm install
  3. mkdir -p storage/logs storage/image
  4. npx pm2-runtime start app.json

Requests then reach Express directly (http://localhost:8080) without Nginx.

First Upload


  1. curl -fsS -X POST \
  2. -F "filepath=@./photo.jpg" \
  3. http://localhost:8080/upload/blog/2025 \
  4. || echo "upload failed"

A successful upload returns 201 (the src below comes from Docker Compose, which sets NODE_ENV: development):
  1. {
  2. "success": 1,
  3. "filename": "ERftP1gTS7WCTeJ8_1744080848530.jpg",
  4. "type": "image/jpeg",
  5. "size": 2501808,
  6. "src": "http://localhost:8080/c/img/blog/2025/ERftP1gTS7WCTeJ8_1744080848530.jpg"
  7. }

First Fetch


  1. # Defaults: WebP, quality 75, long edge shrunk to 1024px when the short edge exceeds 1024px
  2. curl -fsS -o photo.webp \
  3. http://localhost:8080/c/img/blog/2025/ERftP1gTS7WCTeJ8_1744080848530.jpg
  4. # 800px-wide AVIF
  5. curl -fsS -o w800.avif \
  6. "http://localhost:8080/c/img/blog/2025/ERftP1gTS7WCTeJ8_1744080848530.jpg?w=800&t=avif"

The first request converts the image with sharp and writes it to storage/image/cache/; later requests with the same parameters read the cache file.

Next Steps


中文