Skip to content

habibi-dev/express-js-clear

Repository files navigation

Express JS Clear

A modular Express.js starter kit written in TypeScript. The project organizes features into self-contained modules that expose routes, middleware, and scheduled tasks while sharing common infrastructure.

Features

  • TypeScript-first setup with strict compiler configuration.
  • Modular architecture: every module can register its own routes, middleware, and cron jobs.
  • Dynamic loading of routes, middleware, and cron definitions at runtime.
  • Security middleware via helmet and rate limiting on the /api path.
  • CORS configuration allowing cross-origin requests (adjustable for your domain).
  • Static file serving with proper headers for large media files and range requests.
  • Request timing middleware and reusable response handler for consistent API responses.
  • Cron scheduling powered by node-cron.

Getting Started

Prerequisites

  • Node.js 18+
  • npm

Installation

npm install

Running in Development

npm run dev

Runs the project with ts-node. Requests are served over HTTP on localhost.

Building and Running in Production

npm run start

This command compiles TypeScript to the dist directory and starts the HTTPS server. When the DOMAIN environment variable is not localhost, it uses SSL certificates defined by PRIVKEY and FULLCHAIN.

Other Scripts

  • npm run build – compile TypeScript without starting the server.
  • npm test – execute Jest tests located under src/modules/**/tests.

Environment Variables

Variable Description
PORT Port number for the server (default: 3000).
DOMAIN Host name. Use localhost for development.
PRIVKEY Path to the SSL private key (production only).
FULLCHAIN Path to the SSL certificate (production only).

Project Structure

src/
├── config/             # Application and security configuration
├── contracts/          # Shared interfaces for modules
├── crons/              # Cron job registration
├── middleware/         # Global middleware and loader
├── modules/            # Feature modules (routes, middleware, crons)
└── utils/              # Shared utilities

Each module contains its own routes, middleware, crons, and optional tests.

Testing

npm test

Jest looks for test files under src/modules/**/tests.

License

ISC

About

A modular Express.js starter kit written in TypeScript. The project organizes features into self-contained modules that expose routes, middleware, and scheduled tasks while sharing common infrastructure.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors