Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1169

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176
8000 GitHub - NhanPhamThanh-IT/Backend-Express-Template: 🧠 Complete Express.js backend templates with JavaScript & TypeScript implementations. Features user authentication, JWT security, MongoDB integration, and production-ready architecture. Perfect learning resource and starter template for building scalable REST APIs with modern development practices.
Nothing Special   »   [go: up one dir, main page]

Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

🧠 Complete Express.js backend templates with JavaScript & TypeScript implementations. Features user authentication, JWT security, MongoDB integration, and production-ready architecture. Perfect learning resource and starter template for building scalable REST APIs with modern development practices.

License

Notifications You must be signed in to change notification settings

NhanPhamThanh-IT/Backend-Express-Template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Backend Express Tutorial

Node.js Express.js TypeScript JavaScript MongoDB JWT

MIT License GitHub Template PRs Welcome

A comprehensive collection of Express.js backend templates showcasing modern web development practices with both JavaScript and TypeScript implementations. This repository serves as a complete learning resource and production-ready foundation for building scalable backend applications.

🌟 Repository Overview

This repository contains two complete Express.js backend implementations:

  • 🟑 JavaScript Version: Traditional JavaScript implementation with ES6+ features
  • πŸ”· TypeScript Version: Modern TypeScript implementation with full type safety

Both projects demonstrate the same core functionality but showcase different development approaches, allowing you to choose the best fit for your project requirements.

πŸš€ Key Features

Core Functionality

  • βœ… User Authentication System (Register/Login)
  • βœ… JWT Token-Based Security
  • βœ… Password Hashing & Encryption
  • βœ… MongoDB Integration with Mongoose
  • βœ… RESTful API Design
  • βœ… CORS Configuration
  • βœ… Environment-Based Configuration
  • βœ… Middleware Architecture
  • βœ… Error Handling & Validation

Development Features

    8000
  • πŸ”§ Hot Reloading (Development Mode)
  • πŸ“ Comprehensive Documentation
  • πŸ§ͺ Production-Ready Setup
  • πŸ”’ Security Best Practices
  • πŸ“ Clean Architecture Pattern
  • 🎯 API Testing Examples

πŸ“‚ Repository Structure

Backend-Express-Tutorial/
β”œβ”€β”€ πŸ“ JavaScript/              # JavaScript Implementation
β”‚   β”œβ”€β”€ πŸ“„ server.js            # Main server file
β”‚   β”œβ”€β”€ πŸ“„ package.json         # Dependencies & scripts
β”‚   β”œβ”€β”€ πŸ“ config/              # Configuration files
β”‚   β”œβ”€β”€ πŸ“ controllers/         # Business logic
β”‚   β”œβ”€β”€ πŸ“ middleware/          # Custom middleware
β”‚   β”œβ”€β”€ πŸ“ models/              # Database models
β”‚   β”œβ”€β”€ πŸ“ routes/              # API routes
β”‚   └── πŸ“„ README.md            # JavaScript-specific docs
β”‚
β”œβ”€β”€ πŸ“ TypeScript/              # TypeScript Implementation
β”‚   β”œβ”€β”€ πŸ“„ tsconfig.json        # TypeScript configuration
β”‚   β”œβ”€β”€ πŸ“„ package.json         # Dependencies & scripts
β”‚   β”œβ”€β”€ πŸ“ src/                 # Source code
β”‚   β”‚   β”œβ”€β”€ πŸ“„ index.ts         # Application entry point
β”‚   β”‚   β”œβ”€β”€ πŸ“„ server.ts        # Express server setup
β”‚   β”‚   β”œβ”€β”€ πŸ“ config/          # Configuration files
β”‚   β”‚   β”œβ”€β”€ πŸ“ controllers/     # Business logic with types
β”‚   β”‚   β”œβ”€β”€ πŸ“ middleware/      # Type-safe middleware
β”‚   β”‚   β”œβ”€β”€ πŸ“ models/          # Mongoose models with types
β”‚   β”‚   β”œβ”€β”€ πŸ“ routes/          # Type-safe routes
β”‚   β”‚   └── πŸ“ types/           # Type definitions
β”‚   └── πŸ“„ README.md            # TypeScript-specific docs
β”‚
β”œβ”€β”€ πŸ“„ LICENSE                  # MIT License
β”œβ”€β”€ πŸ“„ .gitignore              # Git ignore rules
└── πŸ“„ README.md               # This file

🎯 Quick Start Guide

Prerequisites

1. Clone the Repository

git clone https://github.com/NhanPhamThanh-IT/Backend-Express-Tutorial.git
cd Backend-Express-Tutorial

2. Choose Your Implementation

🟑 JavaScript Version

cd JavaScript
npm install
# Create .env file with your configuration
npm run dev

πŸ”· TypeScript Version

cd TypeScript
npm install
# Create .env file with your configuration
npm run dev

3. Environment Configuration

Create a .env file in your chosen project directory:

PORT=5000
MONGODB_URI=mongodb://localhost:27017/your-database
JWT_SECRET=your-super-secret-jwt-key
CLIENT_URL=http://localhost:3000
NODE_ENV=development

4. Start Development

Your server will be running at http://localhost:5000

πŸ”— API Documentation

Both implementations provide the same API endpoints:

Authentication Endpoints

Method Endpoint Description Request Body
POST /api/v1/auth/register Register new user { fullName, email, password }
POST /api/v1/auth/login User login { email, password }

Example Usage

Register a new user:

curl -X POST http://localhost:5000/api/v1/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "fullName": "John Doe",
    "email": "john@example.com",
    "password": "securePassword123"
  }'

Login user:

curl -X POST http://localhost:5000/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "john@example.com",
    "password": "securePassword123"
  }'

πŸ“š Implementation Comparison

Feature JavaScript TypeScript
Type Safety Runtime checking Compile-time checking
Development Speed Faster initial setup Slower initial setup
Maintainability Good Excellent
IDE Support Good Exceptional
Learning Curve Lower Higher
Production Benefits Good Better error prevention
Team Development Good Better with large teams

πŸ› οΈ Technology Stack

Backend Technologies

  • Express.js: Fast, unopinionated web framework
  • MongoDB: NoSQL database
  • Mongoose: MongoDB object modeling
  • JWT: JSON Web Token authentication
  • bcryptjs: Password hashing library

Development Tools

  • Nodemon: Auto-restart development server
  • TypeScript: (TypeScript version) Static type checking
  • ts-node: (TypeScript version) TypeScript execution

Security & Middleware

  • CORS: Cross-Origin Resource Sharing
  • body-parser: Request body parsing
  • dotenv: Environment variable management

πŸ—οΈ Architecture Patterns

Both implementations follow clean architecture principles:

πŸ“ Config Layer

  • Database connection setup
  • Environment variable management
  • Application configuration

πŸŽ›οΈ Controller Layer

  • Business logic implementation
  • Request/response handling
  • Data validation and processing

πŸ”’ Middleware Layer

  • Authentication verification
  • Request preprocessing
  • Error handling

πŸ“Š Model Layer

  • Database schema definition
  • Data relationships
  • Model methods and validations

πŸ›£οΈ Route Layer

  • API endpoint definitions
  • Route-specific middleware
  • Request routing logic

πŸ”’ Security Features

  • Password Encryption: bcryptjs hashing
  • JWT Authentication: Stateless token-based auth
  • CORS Protection: Configurable cross-origin requests
  • Input Validation: Request data validation
  • Error Sanitization: Safe error responses
  • Environment Isolation: Secure configuration management

πŸ“– Learning Path

Beginner Level

  1. Start with the JavaScript version
  2. Understand Express.js fundamentals
  3. Learn MongoDB and Mongoose basics
  4. Grasp authentication concepts

Intermediate Level

  1. Explore the TypeScript version
  2. Learn type definitions and interfaces
  3. Understand middleware patterns
  4. Practice API testing and debugging

Advanced Level

  1. Compare both implementations
  2. Implement additional features
  3. Add testing suites
  4. Deploy to production

πŸš€ Production Deployment

JavaScript Version

cd JavaScript
npm install --production
npm start

TypeScript Version

cd TypeScript
npm install
npm run build
npm start

Deployment Platforms

  • Heroku: Easy deployment with git integration
  • Vercel: Serverless deployment option
  • DigitalOcean: VPS deployment
  • AWS EC2: Scalable cloud deployment
  • Railway: Simple cloud deployment

πŸ§ͺ Testing the APIs

Using cURL

See the API documentation section above for cURL examples.

Using Postman

  1. Import the API endpoints
  2. Set up environment variables
  3. Test registration and login flows
  4. Verify JWT token authentication

Using VS Code REST Client

Create a .http file with:

### Register User
POST http://localhost:5000/api/v1/auth/register
Content-Type: application/json

{
  "fullName": "John Doe",
  "email": "john@example.com",
  "password": "securePassword123"
}

### Login User
POST http://localhost:5000/api/v1/auth/login
Content-Type: application/json

{
  "email": "john@example.com",
  "password": "securePassword123"
}

πŸ”„ Version History

  • v1.0.0 - Initial release with JavaScript and TypeScript implementations
  • Features: Complete authentication system, MongoDB integration, JWT security

🀝 Contributing

We welcome contributions! Here's how you can help:

How to Contribute

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

Contribution Guidelines

  • Follow the existing code style
  • Add appropriate comments and documentation
  • Test your changes thoroughly
  • Update README if necessary
  • Ensure both JavaScript and TypeScript versions work

Areas for Contribution

  • πŸ§ͺ Testing: Add unit and integration tests
  • πŸ“ Documentation: Improve or translate documentation
  • πŸ”’ Security: Enhance security features
  • ⚑ Performance: Optimize code performance
  • 🎨 UI: Add frontend examples
  • πŸ”Œ Features: Implement new functionality

πŸ“ž Support & Community

Getting Help

Connect with the Community

  • ⭐ Star this repository if you find it helpful
  • 🍴 Fork to create your own version
  • πŸ“’ Share with other developers

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

License Summary

  • βœ… Commercial use
  • βœ… Modification
  • βœ… Distribution
  • βœ… Private use
  • ❌ Liability
  • ❌ Warranty

πŸ‘¨β€πŸ’» Author

Nhan Pham Thanh

🌟 Acknowledgments

Special thanks to:

  • Express.js Team for the amazing framework
  • MongoDB Team for the robust database solution
  • TypeScript Team for bringing type safety to JavaScript
  • Open Source Community for continuous inspiration
  • Contributors who help improve this project

πŸ“š Additional Resources

Official Documentation

Learning Materials


⭐ Star this repository if it helped you build better Express.js applications! ⭐

Made with ❀️ by Nhan Pham Thanh

Building the future, one API at a time πŸš€

About

🧠 Complete Express.js backend templates with JavaScript & TypeScript implementations. Features user authentication, JWT security, MongoDB integration, and production-ready architecture. Perfect learning resource and starter template for building scalable REST APIs with modern development practices.

Topics

Resources

License

Stars

Watchers

Forks

0