Coder Social home page Coder Social logo

edwinhern / express-typescript-2024 Goto Github PK

View Code? Open in Web Editor NEW
379.0 7.0 82.0 839 KB

Express + TypeScript + Boilerplate for Web / API App

TypeScript 98.42% Dockerfile 1.10% Shell 0.48%
express typescript bolierplate docker docker-compose express-docker-compose express-typescript express-typescript-boilerplate express-typescript-tutorial expresstypescript

express-typescript-2024's Introduction

๐Ÿš€ Express TypeScript Boilerplate 2024

Build Test Code Quality Docker Image CI

๐ŸŒŸ 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.
  • ๐Ÿ”„ Renovate 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: Biomejs 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

๐Ÿค 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 karl-friman 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  avatar

express-typescript-2024's Issues

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.

Error Run : npm run dev

Error that i facing was :


โฏ npm run dev

> [email protected] dev
> tsx watch --clear-screen=false src/index.ts | pino-pretty

================================
 Invalid environment variables:
    COMMON_RATE_LIMIT_MAX_REQUESTS: Invalid number input: ""20" # Max number of requests per window per IP"
    COMMON_RATE_LIMIT_WINDOW_MS: Invalid number input: ""1000" # Window size for rate limiting (ms)"
    HOST: Invalid host (domain or ip): ""localhost"       # Hostname for the server"
    NODE_ENV: Value ""development" # Options: 'development', 'production'" not in choices [development,production,test]
    PORT: Invalid port input: ""8080"            # The port your server will listen on"
================================

 Exiting with error code 1

Protect route with auth middleware

Hi.

Greate boilerplate. You can add a auth middleware to protect some route. I have an implementation in mind. Can submit a PR if you are not already working on it.

Request is not typed

request with type Request in route's controller is not strictly-typed to zod schema

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\"",

Dependency Dashboard

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

Open

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

Detected dependencies

dockerfile
Dockerfile
  • node 22.5-slim
github-actions
.github/workflows/build.yml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/code-quality.yml
  • actions/checkout v4
  • biomejs/setup-biome v2
.github/workflows/docker-image.yml
  • actions/checkout v4
  • docker/login-action v3
.github/workflows/test.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 ^10.0.0
  • swagger-ui-express ^5.0.0
  • zod ^3.22.4
  • @biomejs/biome 1.8.3
  • @types/cors ^2.8.17
  • @types/express ^4.17.21
  • @types/supertest ^6.0.2
  • @types/swagger-ui-express ^4.1.6
  • husky ^9.0.11
  • lint-staged ^15.2.2
  • pino-pretty ^11.0.0
  • rimraf ^6.0.0
  • supertest ^7.0.0
  • tsup ^8.0.2
  • tsx ^4.7.2
  • typescript ^5.4.4
  • vite-tsconfig-paths ^4.3.2
  • vitest ^2.0.0
nvm
.nvmrc
  • node 22.5.1
regex
biome.json
  • @biomejs/biome 1.8.3

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

Thank you!

Your project is a breathe of fresh air. Thank you for not over-complicating the functionality - it's just right! Appreciated

Unable to send post requests

There seems to be code missing for adding post requests. I have tried for several hours to send a post request but I am getting undefined bodies etc.

One of the missing peaces for sure was :

app.use(express.json());
app.use(express.urlencoded())

but that didnt help. It just removed one problem.

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.