Code Monkey home page Code Monkey logo

edwinhern / express-typescript-2024 Goto Github PK

View Code? Open in Web Editor NEW
236.0 236.0 49.0 758 KB

Express + TypeScript + Boilerplate for Web / API App

Home Page: https://express.hernandezserver.com/

License: MIT License

TypeScript 95.22% Dockerfile 1.09% Shell 0.79% JavaScript 2.91%
bolierplate docker docker-compose exception-handling express express-docker-compose express-typescript express-typescript-boilerplate express-typescript-tutorial expresstypescript jest logging ts-jest typescript

express-typescript-2024's Introduction

๐Ÿš€ Express TypeScript Boilerplate 2024

Build Express Application CodeQL Docker Image CI Release

๐ŸŒŸ Introduction

Welcome to the Express TypeScript Boilerplate 2024 โ€“ a streamlined, efficient, and scalable foundation for building powerful backend services. This boilerplate merges modern tools and practices in Express.js and TypeScript, enhancing productivity, code quality, and performance.

๐Ÿ’ก Motivation and Intentions

Developed to streamline backend development, this boilerplate is your solution for:

  • โœจ Reducing setup time for new projects.
  • ๐Ÿ“Š Ensuring code consistency and quality.
  • โšก Facilitating rapid development with cutting-edge tools.
  • ๐Ÿ›ก๏ธ Encouraging best practices in security, testing, and performance.

๐Ÿš€ Features

  • ๐Ÿ“ Modular Structure: Organized by feature for easy navigation and scalability.
  • ๐Ÿ’จ Faster Execution with tsx: Rapid TypeScript execution with esbuild, complemented by tsc for type checking.
  • ๐ŸŒ Stable Node Environment: Latest LTS Node version in .nvmrc.
  • ๐Ÿ”ง Simplified Environment Variables with Envalid: Centralized and easy-to-manage configuration.
  • ๐Ÿ”— Path Aliases: Cleaner code with shortcut imports.
  • ๐Ÿ”„ Dependabot Integration: Automatic updates for secure and up-to-date dependencies.
  • ๐Ÿ”’ Security: Helmet for HTTP header security and CORS setup.
  • ๐Ÿ“Š Logging: Efficient logging with pino-http.
  • ๐Ÿงช Comprehensive Testing: Robust setup with Vitest and Supertest.
  • ๐Ÿ”‘ Code Quality Assurance: Husky and lint-staged for consistent quality.
  • โœ… Unified Code Style: ESLint and Prettier for a consistent coding standard.
  • ๐Ÿ“ƒ API Response Standardization: ServiceResponse class for consistent API responses.
  • ๐Ÿณ Docker Support: Ready for containerization and deployment.
  • ๐Ÿ“ Input Validation with Zod: Strongly typed request validation using Zod.
  • ๐Ÿงฉ API Spec Generation: Automated OpenAPI specification generation from Zod schemas to ensure up-to-date and accurate API documentation.

๐Ÿ› ๏ธ Getting Started

Step 1: ๐Ÿš€ Initial Setup

  • Clone the repository: git clone https://github.com/edwinhern/express-typescript-2024.git
  • Navigate: cd express-typescript-2024
  • Install dependencies: npm ci

Step 2: โš™๏ธ Environment Configuration

  • Create .env: Copy .env.template to .env
  • Update .env: Fill in necessary environment variables

Step 3: ๐Ÿƒโ€โ™‚๏ธ Running the Project

  • Development Mode: npm run dev
  • Building: npm run build
  • Production Mode: Set .env to NODE_ENV="production" then npm run build && npm run start

๐Ÿ“ Project Structure

.
โ”œโ”€โ”€ api
โ”‚   โ”œโ”€โ”€ healthCheck
โ”‚   โ”‚   โ”œโ”€โ”€ __tests__
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ healthCheckRouter.test.ts
โ”‚   โ”‚   โ””โ”€โ”€ healthCheckRouter.ts
โ”‚   โ””โ”€โ”€ user
โ”‚       โ”œโ”€โ”€ __tests__
โ”‚       โ”‚   โ”œโ”€โ”€ userRouter.test.ts
โ”‚       โ”‚   โ””โ”€โ”€ userService.test.ts
โ”‚       โ”œโ”€โ”€ userModel.ts
โ”‚       โ”œโ”€โ”€ userRepository.ts
โ”‚       โ”œโ”€โ”€ userRouter.ts
โ”‚       โ””โ”€โ”€ userService.ts
โ”œโ”€โ”€ api-docs
โ”‚   โ”œโ”€โ”€ __tests__
โ”‚   โ”‚   โ””โ”€โ”€ openAPIRouter.test.ts
โ”‚   โ”œโ”€โ”€ openAPIDocumentGenerator.ts
โ”‚   โ”œโ”€โ”€ openAPIResponseBuilders.ts
โ”‚   โ””โ”€โ”€ openAPIRouter.ts
โ”œโ”€โ”€ common
โ”‚   โ”œโ”€โ”€ __tests__
โ”‚   โ”‚   โ”œโ”€โ”€ errorHandler.test.ts
โ”‚   โ”‚   โ””โ”€โ”€ requestLogger.test.ts
โ”‚   โ”œโ”€โ”€ middleware
โ”‚   โ”‚   โ”œโ”€โ”€ errorHandler.ts
โ”‚   โ”‚   โ”œโ”€โ”€ rateLimiter.ts
โ”‚   โ”‚   โ””โ”€โ”€ requestLogger.ts
โ”‚   โ”œโ”€โ”€ models
โ”‚   โ”‚   โ””โ”€โ”€ serviceResponse.ts
โ”‚   โ””โ”€โ”€ utils
โ”‚       โ”œโ”€โ”€ commonValidation.ts
โ”‚       โ”œโ”€โ”€ envConfig.ts
โ”‚       โ””โ”€โ”€ httpHandlers.ts
โ”œโ”€โ”€ index.ts
โ””โ”€โ”€ server.ts

๐Ÿค Feedback and Contributions

We'd love to hear your feedback and suggestions for further improvements. Feel free to contribute and join us in making backend development cleaner and faster!

๐ŸŽ‰ Happy coding!

express-typescript-2024's People

Contributors

1001josias avatar dependabot[bot] avatar edwinhern avatar github-actions[bot] avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

express-typescript-2024's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): lock file maintenance

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

dockerfile
Dockerfile
github-actions
.github/workflows/build.yml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/codeql.yml
  • actions/checkout v4
  • github/codeql-action v3
  • github/codeql-action v3
  • github/codeql-action v3
.github/workflows/docker-image.yml
  • actions/checkout v4
  • docker/login-action v3
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-node v4
npm
package.json
  • @asteasolutions/zod-to-openapi ^7.0.0
  • cors ^2.8.5
  • dotenv ^16.4.5
  • envalid ^8.0.0
  • express ^4.19.2
  • express-rate-limit ^7.2.0
  • helmet ^7.1.0
  • http-status-codes ^2.3.0
  • pino-http ^9.0.0
  • swagger-ui-express ^5.0.0
  • zod ^3.22.4
  • @commitlint/cli ^19.2.1
  • @commitlint/config-conventional ^19.1.0
  • @semantic-release/changelog ^6.0.3
  • @semantic-release/git ^10.0.1
  • @semantic-release/github ^10.0.3
  • @types/cors ^2.8.17
  • @types/express ^4.17.21
  • @types/supertest ^6.0.2
  • @types/swagger-ui-express ^4.1.6
  • @typescript-eslint/eslint-plugin ^7.5.0
  • @typescript-eslint/parser ^7.5.0
  • @vitest/coverage-v8 ^1.4.0
  • eslint ^8.57.0
  • eslint-config-prettier ^9.1.0
  • eslint-plugin-prettier ^5.1.3
  • eslint-plugin-simple-import-sort ^12.0.0
  • husky ^9.0.11
  • lint-staged ^15.2.2
  • pino-pretty ^11.0.0
  • prettier ^3.2.5
  • rimraf ^5.0.5
  • semantic-release ^23.0.8
  • supertest ^7.0.0
  • tsup ^8.0.2
  • tsx ^4.7.2
  • typescript ^5.4.4
  • vite-tsconfig-paths ^4.3.2
  • vitest ^1.3.1
nvm
.nvmrc

  • Check this box to trigger a request for Renovate to run again on this repository

Not compiling TS with `npm run dev`

It looks like that the TS code is not being recompiled when there's a change.
Did I miss something?

Here's my workaround:

    "dev": "tsc-watch --noClear --onSuccess \"tsx ./dist/index.js\"",

Help Wanted: Implementing JWT Authentication for API Routes

Overview

We are planning to integrate JWT-based authentication into our existing API. This feature aims to secure our routes while providing flexibility to exempt certain routes from requiring authentication. Additionally, we want to ensure that our Swagger documentation accurately reflects the authentication requirements for each route.

Requirements

  • Implement JWT authentication middleware that can be easily applied to selected routes.
  • Ensure a mechanism is in place to mark certain routes as public (no authentication required) while defaulting to private (authentication required).
  • Update our Swagger/OpenAPI documentation to reflect the authentication status of each route, enhancing clarity for API consumers.

Proposed Solution

I propose the development of a reusable function or middleware that encapsulates the following functionalities:

  • JWT Authentication: A middleware that validates JWT tokens for protected routes.
  • Route Configuration: Enhance our route setup to include authentication requirements. This could be a flag or setting within the route's configuration.
  • Swagger Documentation: Automatically update our OpenAPI documentation based on the route's authentication requirements.

Example Concept

Here's a conceptual approach to how we might define a route with this new system:

image

Contribution Guidelines

  • Fork the repository and create a new branch for your feature.
  • Write clean, readable, and well-documented code.
  • Ensure that existing tests pass and write new tests as necessary to cover the authentication functionality.
  • Update the README and any relevant documentation to reflect the changes.
  • Submit a pull request with a clear description of the changes and any other relevant information.

Discussion

I'm open to ideas on how best to implement this feature and would love to collaborate with anyone interested in contributing. If you have experience with JWT authentication or have suggestions on improving this proposal, please feel free to share your thoughts or submit a pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.