Skip to content
/ bend Public

Bend - The modern backend project generator and bundler. Create production-ready backend apps instantly with your favorite stack - TypeScript or JavaScript, Express or Fastify, Prisma or Mongoose - all preconfigured with nodemon, esbuild, and smart templates

License

Notifications You must be signed in to change notification settings

bendhq/bend

Repository files navigation

Bend Logo

Bend - The Backend Bundler

npm version CI License: MIT Node.js Version Bun Version

Bend is a production-ready backend scaffolder that creates secure, optimized backend projects with enterprise-grade features baked in from day one.

Why Bend?

  • Production-Ready Security: helmet(), cors(), rate limiting, and HPP protection out of the box
  • Enterprise Logging: Winston with daily rotation, structured metadata, and HTTP request logging
  • Smart Detection: Auto-detects runtime (Node.js/Bun) and package manager (npm/pnpm/yarn/bun)
  • Multiple Stacks: 8 template combinations (TypeScript/JavaScript × Express/Fastify × Mongoose/Prisma)
  • Zero Configuration: Works immediately, customizable when needed
  • TypeScript First: Full TypeScript support with strict mode enabled

Quick Start

Recommended: Using npm create

# Latest version
npm create bend@latest

# With project name
npm create bend@latest my-backend

Other Package Managers

# Using pnpm
pnpm create bend

# Using yarn
yarn create bend

# Using bun
bunx create-bend

What You Get

Every Bend project includes:

Security (Production-Ready)

  • helmet - Sets security HTTP headers
  • cors - Configurable cross-origin resource sharing
  • rate-limit - DDoS protection (100 req/15min per IP)
  • hpp - HTTP parameter pollution prevention
  • Body size limits - Prevents memory exhaustion (10MB default)
  • Error sanitization - Hides sensitive info in production
  • Compression - gzip/deflate response compression

Logging & Monitoring

  • Winston - Enterprise-grade logging
  • Daily log rotation - Automatic archival (30-day retention)
  • Separate log files - error.log, combined.log, exceptions.log
  • HTTP request logging - Morgan middleware integration
  • Structured metadata - JSON format for easy parsing
  • Production-ready - Compatible with DataDog, Splunk, ELK, CloudWatch

Error Handling

  • Async error handling - express-async-errors for cleaner code
  • Centralized error middleware - Single point for error handling
  • Graceful shutdown - Proper cleanup on SIGTERM/SIGINT
  • Unhandled rejection handlers - No silent crashes

Developer Experience

  • TypeScript strict mode - Maximum type safety
  • ESLint + Prettier - Code quality and formatting
  • Environment variables - .env file support with dotenv
  • Project structure - Clean, scalable architecture
  • Example models - User model to get started quickly

Tech Stack Options

Runtimes

  • Node.js (≥18.0.0) - Auto-detected
  • Bun (≥1.0.0) - Auto-detected

Languages

  • TypeScript (Recommended) - Full type safety
  • JavaScript (ESM) - Modern JavaScript

Frameworks

  • Express - Battle-tested, extensive ecosystem
  • Fastify - High performance, modern

Databases/ORMs

  • MongoDB + Mongoose - NoSQL with schema validation
  • SQL + Prisma - PostgreSQL, MySQL, SQLite support

Total: 8 template combinations

Generated Project Structure

my-backend/
├── src/
│   ├── config/
│   │   ├── database.ts      # Database connection with retry logic
│   │   └── logger.ts        # Winston logger with daily rotation
│   ├── controllers/         # Route controllers
│   │   └── health.controller.ts
│   ├── models/              # Database models
│   │   └── User.model.ts    # Example user model
│   ├── routes/              # Express/Fastify routes
│   │   └── health.routes.ts
│   ├── services/            # Business logic layer
│   ├── middlewares/         # Custom middlewares
│   ├── utils/               # Utility functions
│   ├── app.ts               # App configuration + middlewares
│   └── server.ts            # Server entry point + graceful shutdown
├── logs/                    # Auto-generated log directory
│   ├── combined-YYYY-MM-DD.log
│   ├── error-YYYY-MM-DD.log
│   └── exceptions-YYYY-MM-DD.log
├── .env                     # Environment variables
├── .gitignore
├── package.json
├── tsconfig.json            # TypeScript strict mode
└── README.md                # Project-specific README

Example: What Your API Includes

// src/app.ts - Security & Logging (Auto-generated)

import helmet from 'helmet';
import cors from 'cors';
import rateLimit from 'express-rate-limit';
import hpp from 'hpp';
import compression from 'compression';
import morgan from 'morgan';
import logger from './config/logger';

const app = express();

// Security
app.use(helmet());              // Security headers
app.use(cors({ /* config */ })); // CORS
app.use(hpp());                 // Parameter pollution prevention

// Rate limiting
const limiter = rateLimit({
  windowMs: 15 * 60 * 1000,    // 15 minutes
  max: 100,                     // 100 requests per IP
});
app.use('/api/', limiter);

// Logging
app.use(morgan('combined', {
  stream: { write: (msg) => logger.info(msg.trim()) }
}));

// Compression
app.use(compression());

// Your routes...
// src/config/logger.ts - Winston Logger (Auto-generated)

import winston from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    new DailyRotateFile({
      filename: 'logs/error-%DATE%.log',
      level: 'error',
      maxFiles: '30d',
    }),
    new DailyRotateFile({
      filename: 'logs/combined-%DATE%.log',
      maxFiles: '30d',
    }),
  ],
});

Published Packages

Bend is published as three npm packages:

1. create-bend (Recommended)

Initializer package used via npm create bend.

npm create bend@latest

What it does: Downloads and runs bend-core automatically.

2. bend-core

Core library with all templates and scaffolding logic.

npx bend-core

Use case: Direct usage or programmatic access.

3. bendjs

Global CLI wrapper (optional).

npm install -g bendjs
bend

Use case: For users who prefer global installation.

Development

Prerequisites

  • Node.js ≥18.0.0
  • pnpm (recommended)

Setup

# Clone repository
git clone https://github.com/bendhq/bend.git
cd bend

# Install dependencies
pnpm install

# Build all packages
pnpm build

# Run linting
pnpm lint

# Format code
pnpm format

Project Structure (Monorepo)

bend/
├── packages/
│   ├── create-bend/        # npm create initializer
│   │   ├── bin/
│   │   │   └── index.js    # Delegates to bend-core
│   │   └── package.json
│   ├── bend-cli/           # Global CLI wrapper (bendjs)
│   │   ├── bin/
│   │   │   └── bend.js     # Wrapper script
│   │   └── package.json
│   └── bend-core/          # Core library
│       ├── src/
│       │   ├── cli/        # CLI implementation
│       │   ├── scaffold/   # Project scaffolding
│       │   │   └── templates/  # All 8 templates
│       │   ├── types/      # TypeScript types
│       │   └── utils/      # Utilities
│       └── package.json
├── scripts/                # Build scripts
├── .github/
│   └── workflows/
│       └── ci.yml          # CI/CD pipeline
├── package.json            # Root package
├── pnpm-workspace.yaml     # Workspace config
└── tsconfig.json           # TypeScript config

Testing Locally

# Test CLI locally
node packages/bend-core/dist/cli/index.js my-test-project

# Test with specific options
node packages/bend-core/dist/cli/index.js my-app --no-install

Environment Variables

Configure your generated project via .env:

# Server
PORT=3000
NODE_ENV=development

# Database (MongoDB example)
MONGODB_URI=mongodb://localhost:27017/myapp

# Database (Prisma example)
DATABASE_URL="postgresql://user:password@localhost:5432/mydb"

# Security
CORS_ORIGIN=https://yourdomain.com

# Logging
LOG_LEVEL=info  # error | warn | info | debug

Roadmap

  • Core CLI functionality
  • Multiple runtime support (Node.js, Bun)
  • Express & Fastify frameworks
  • Mongoose & Prisma ORMs
  • TypeScript & JavaScript
  • Security middlewares (helmet, cors, rate-limit, hpp)
  • Winston logging with daily rotation
  • GitHub Actions CI/CD
  • ESLint + Prettier
  • Docker support
  • Authentication templates (JWT, OAuth)
  • Testing setup (Jest)
  • API documentation (Swagger/OpenAPI)
  • GraphQL support
  • Microservices templates

Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT © Bend

Links

Credits

Built with:


Bend - Production-ready backends in seconds, not hours.

About

Bend - The modern backend project generator and bundler. Create production-ready backend apps instantly with your favorite stack - TypeScript or JavaScript, Express or Fastify, Prisma or Mongoose - all preconfigured with nodemon, esbuild, and smart templates

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published