Deploying an Anchr App
Introduction
Anchr is a lightweight, open-source toolbox for everyday tasks on the internet. It offers three core features:
- Link shortening – create short, shareable URLs with optional malicious-link checking via Google Safe Browsing.
- Bookmark collections – searchable, categorized bookmark lists accessible from any device.
- Encrypted image uploads – share images securely with client-side encryption.
Built on Node.js with an AngularJS frontend and MongoDB backend, Anchr is ideal for personal or team use when you want full control over your data. Deploying Anchr on Klutch.sh gives you automated builds from GitHub, managed secrets, persistent storage for uploads, and hassle-free HTTPS—no server maintenance required.
This guide walks you through deploying Anchr on Klutch.sh using a Dockerfile, configuring the required MongoDB database, setting up environment variables, attaching persistent volumes, and verifying the deployment.
Features overview
| Feature | Description |
|---|---|
| Link shortener | Generate compact URLs; optionally verify against Safe Browsing API |
| Bookmark collections | Organize links by category with full-text search |
| Encrypted images | Upload images with client-side AES encryption |
| OAuth login | Google and Facebook authentication support |
| Telegram bot | Interact with Anchr via @AnchrBot |
| Prometheus metrics | Expose /api/metrics for monitoring |
| REST API | Integrate with ShareX, browser extensions, and custom scripts |
Prerequisites
Before you begin, ensure you have:
- A Klutch.sh account
- A GitHub repository (fork or clone of the official Anchr repo)
- A running MongoDB instance (deploy on Klutch.sh or use a managed service like MongoDB Atlas)
- Basic familiarity with Docker and environment variables
- (Optional) A Google API key for Safe Browsing link checks
- (Optional) OAuth credentials for Google or Facebook login
Architecture overview
Anchr consists of:
| Component | Technology | Notes |
|---|---|---|
| Backend | Node.js 21, Express | Serves API and static frontend |
| Frontend | AngularJS, Bower | Built during Docker image creation |
| Database | MongoDB 6+ | Stores users, links, collections, images metadata |
| Storage | File system | Uploaded images written to /app/data |
The application listens on port 3000 by default. On Klutch.sh, you’ll set this as the internal port to route HTTP traffic.
Deployment steps
-
Prepare your GitHub repository
Fork or clone the Anchr repository to your own GitHub account. The repo already includes a production-ready
Dockerfile, so no changes are needed for basic deployments.Terminal window git clone https://github.com/muety/anchr.gitcd anchrgit remote set-url origin https://github.com/YOUR_USERNAME/anchr.gitgit push -u origin masterKlutch.sh automatically detects the
Dockerfilein the repository root and uses it for the build—no manual selection is required. -
Deploy MongoDB on Klutch.sh (or use an external database)
Anchr requires MongoDB. You can either use a managed service like MongoDB Atlas or deploy MongoDB on Klutch.sh as a separate app.
Option A: MongoDB Atlas (recommended for production)
- Create a free cluster at MongoDB Atlas.
- Add a database user and whitelist your Klutch.sh app’s IP (or allow access from anywhere for simplicity).
- Copy the connection string (e.g.,
mongodb+srv://user:pass@cluster.mongodb.net/anchr).
Option B: Deploy MongoDB on Klutch.sh
- In klutch.sh/app, create a new app within your project.
- Connect a GitHub repo containing a simple MongoDB Dockerfile:
FROM mongo:6EXPOSE 27017CMD ["mongod", "--bind_ip_all"]- Select TCP traffic and set the internal port to 27017.
- Attach a persistent volume with mount path
/data/dband size 20 GB (adjust based on expected data). - Deploy the app. You can connect to the database at
your-mongo-app.klutch.sh:8000from your Anchr app.
-
Create a new Anchr app on Klutch.sh
- Log in to klutch.sh/app.
- Create a new project (if you don’t have one) by clicking New Project.
- Inside your project, click New App.
- Connect your GitHub repository containing the Anchr source code.
- Klutch.sh will detect the
Dockerfileautomatically and begin building.
-
Configure environment variables
In the Klutch.sh dashboard, navigate to your Anchr app’s Settings → Environment Variables and add the following. Mark sensitive values (passwords, secrets, API keys) as secrets.
Required variables:
Terminal window # ServerPORT=3000LISTEN_ADDR=0.0.0.0ANCHR_PUBLIC_URL=https://example-app.klutch.sh# Database (adjust host/port based on your MongoDB setup)ANCHR_DB_HOST=your-mongo-app.klutch.shANCHR_DB_PORT=8000ANCHR_DB_NAME=anchrANCHR_DB_USER=anchrANCHR_DB_PASSWORD=your-secure-password# Uploads & logsANCHR_UPLOAD_DIR=/app/dataANCHR_LOG_PATH=/app/data/logs/access.logANCHR_ERROR_LOG_PATH=/app/data/logs/error.log# SecurityANCHR_SECRET=generate-a-long-random-stringOptional variables:
Terminal window # Google Safe Browsing (link safety checks)ANCHR_GOOGLE_API_KEY=your-google-api-key# OAuth (Google login)ANCHR_GOOGLE_CLIENT_ID=your-google-client-idANCHR_GOOGLE_SECRET=your-google-client-secret# OAuth (Facebook login)ANCHR_FB_CLIENT_ID=your-facebook-client-idANCHR_FB_SECRET=your-facebook-client-secret# User registrationANCHR_ALLOW_SIGNUP=trueANCHR_VERIFY_USERS=false# MonitoringANCHR_EXPOSE_METRICS=true# SMTP for email verification (if ANCHR_VERIFY_USERS=true)ANCHR_SMTP_HOST=smtp.example.comANCHR_SMTP_PORT=587ANCHR_SMTP_USER=your-smtp-userANCHR_SMTP_PASS=your-smtp-passwordANCHR_MAIL_SENDER=Anchr <noreply@example.com> -
Configure the internal port
In your Anchr app’s settings:
- Select HTTP traffic.
- Set the internal port to 3000 (Anchr’s default).
Klutch.sh will route external HTTPS traffic to port 3000 inside your container.
-
Attach persistent storage
Anchr stores uploaded images on the file system. To persist these across deployments:
- Navigate to Storage in your app’s settings.
- Click Add Volume.
- Configure:
- Mount path:
/app/data - Size: 50 GB (adjust based on expected uploads)
- Mount path:
- Save the volume.
This ensures uploaded images, logs, and any other data written to
/app/datasurvive container restarts and redeployments. -
Deploy the application
- Push any final changes to your GitHub repository.
- In the Klutch.sh dashboard, click Deploy (or trigger a redeploy if already created).
- Monitor the build logs for any errors.
- Once the build completes, your Anchr instance will be available at
https://example-app.klutch.sh.
-
Verify the deployment
- Open
https://example-app.klutch.shin your browser. - You should see the Anchr login/signup page.
- Create an account (if
ANCHR_ALLOW_SIGNUP=true). - Test each feature:
- Create a shortlink and verify it redirects.
- Add a bookmark collection.
- Upload an image (optionally with encryption).
- If you enabled metrics, verify at
https://example-app.klutch.sh/api/metrics.
- Open
Sample Dockerfile
The official Anchr repository includes a Dockerfile. Here’s a reference version with explanations:
FROM node:21-alpine
WORKDIR /app
# Copy application filesCOPY app /app/app/COPY config /app/config/COPY lib /app/lib/COPY public /app/public/COPY *.js /app/COPY *.json /app/
# Create data volume mount pointVOLUME [ "/app/data" ]
# Install dependenciesRUN apk update && apk upgrade && \ apk add --no-cache bash git openssh
# Install Bower globally and project dependenciesRUN npm install -g bower && \ npm install && \ cd public && \ bower install --allow-root && \ cd .. && \ npm run build && \ mkdir -p /var/log/anchr /app/data/logs
# Expose default portEXPOSE 3000
# Start production serverENTRYPOINT ["npm", "run", "production"]Key points:
- Uses Node.js 21 Alpine for a lightweight image.
- Installs Bower (legacy dependency manager still used by Anchr’s frontend).
- Builds frontend assets during image creation for faster startup.
- Creates log directories at build time.
- Exposes port 3000 (Anchr’s default).
Environment variables reference
| Variable | Default | Description |
|---|---|---|
PORT | 3000 | TCP port the server listens on |
LISTEN_ADDR | 127.0.0.1 | IP address to bind (use 0.0.0.0 in containers) |
ANCHR_PUBLIC_URL | http://localhost:3000 | Public URL (no trailing slash) |
ANCHR_DB_HOST | localhost | MongoDB host |
ANCHR_DB_PORT | 27017 | MongoDB port |
ANCHR_DB_NAME | anchr | Database name |
ANCHR_DB_USER | anchr | Database user |
ANCHR_DB_PASSWORD | — | Database password (required) |
ANCHR_UPLOAD_DIR | /var/data/anchr | Directory for uploaded images |
ANCHR_SECRET | shhh | JWT signing secret (use a long random string) |
ANCHR_LOG_PATH | /var/log/anchr/access.log | Access log file path |
ANCHR_ERROR_LOG_PATH | /var/log/anchr/error.log | Error log file path |
ANCHR_GOOGLE_API_KEY | — | Google Safe Browsing API key |
ANCHR_ALLOW_SIGNUP | true | Allow new user registrations |
ANCHR_VERIFY_USERS | true | Require email verification |
ANCHR_EXPOSE_METRICS | false | Expose Prometheus metrics endpoint |
Persistent storage paths
| Mount path | Purpose | Recommended size |
|---|---|---|
/app/data | Uploaded images and logs | 50–100 GB |
/data/db (MongoDB app) | Database files | 20–50 GB |
Connecting Anchr to MongoDB on Klutch.sh
If you deployed MongoDB as a separate Klutch.sh app with TCP traffic:
- Note your MongoDB app’s URL (e.g.,
my-mongo.klutch.sh). - The external port for TCP apps is 8000.
- Set these environment variables in your Anchr app:
ANCHR_DB_HOST=my-mongo.klutch.shANCHR_DB_PORT=8000Ensure the MongoDB app has authentication enabled and a user created for the anchr database.
Troubleshooting
| Symptom | Solution |
|---|---|
MongoServerError: Authentication failed | Verify ANCHR_DB_USER and ANCHR_DB_PASSWORD match the MongoDB user credentials. |
| Uploads lost after redeploy | Ensure /app/data is mounted to a persistent volume. |
EADDRINUSE: address already in use | Check that PORT matches the internal port configured in Klutch.sh (default 3000). |
| Shortlinks not created | If using Safe Browsing, verify ANCHR_GOOGLE_API_KEY is valid. |
| Email verification not sending | Configure SMTP variables or disable verification with ANCHR_VERIFY_USERS=false. |
| Build fails on Bower install | The Dockerfile handles this; ensure you’re using the official Dockerfile without modifications. |
Security best practices
- Generate strong secrets: Use a long, random string for
ANCHR_SECRET. - Use Klutch.sh secrets: Mark database passwords and API keys as secrets in the environment variables UI.
- Restrict signups: Set
ANCHR_ALLOW_SIGNUP=falseafter creating your account if you don’t want public registrations. - Enable HTTPS: Klutch.sh provides automatic HTTPS for all deployed apps.
- Rotate credentials: Periodically update database passwords and JWT secrets.
Next steps
- Review the Monitoring guide to set up log streaming and alerts.
- Configure a custom domain using the Custom Domains documentation.
- Explore Anchr’s browser extension for quick link saving and shortening.
- Set up the Android app for mobile access.