Skip to content

KubeRocketCI/template-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js + Express + TypeScript Template

This is a template for building backend applications using Node.js, Express, and TypeScript. It includes TypeScript configuration, Express setup, a structured project organization, and commonly used middleware.


Features

  • 📝 TypeScript for type-safe development.
  • 🚀 Pre-configured Express server.
  • 🔧 Easy-to-understand project structure.

Getting Started

Prerequisites

Make sure you have the following installed:

  • Node.js (v22 or later)
  • npm

Installation

  1. Clone the repository:
  2. Install dependencies:
    npm install

Scripts

Scripts

Here are the detailed commands explained for this project:

  • Build the project:
    npm run build
    Compiles the TypeScript code (src/) into JavaScript and places the output in the dist/ folder. This is done using the TypeScript compiler (tsc).
  • Run app locally::
    npm run start
    Runs the server using Node.js by executing the compiled JavaScript file located in dist/server.js. This assumes your entry point is src/server.ts (compiled to dist/server.js). The server listens on http://localhost:8080.
  • Run the development server::
    npm run dev
    Starts the server in development mode with hot-reloading. This uses nodemon to watch changes in files matching the pattern src/**/*.ts and automatically restarts the server. ts-node is used to directly execute TypeScript files without prior compilation. The server listens on http://localhost:8080.
  • Lint the project::
    npm run lint
    Runs ESLint to analyze and report TypeScript/JavaScript code issues in the src/ directory. Automatically enforces best practices and catches potential errors.

Project Structure

The project is organized as follows:

node-express-ts-template/
├── src/
│   ├── controllers/              # Business logic for routes
│   │   └── hello-world
│   ├── middlewares/              # Custom middlewares
│   │   └── error-handler         # Example middleware
│   ├── models/                   # Application models (e.g., database schemas or data structures)
│   │   └── example.model.ts      # Example model
│   ├── routes/                   # API routes
│   │   └── hello-world.route.ts  # Example route
│   ├── app.ts                    # Express app setup
│   ├── server.ts                 # Entry point of the application
├── dist/                         # Compiled JavaScript output (generated)
├── .eslintrc.js                  # ESLint configuration
├── .gitignore                    # Files ignored by Git
├── .nvmrc                        # Node.js version configuration for nvm
├── package.json                  # Project dependencies and metadata
├── package-lock.json             # Exact dependency versions
├── README.md                     # Project documentation
├── tsconfig.json                 # TypeScript configuration

Example Usage

The server runs on http://localhost:8080.

Example Route: /api/hello

This project includes a sample route to demonstrate the structure. Access it by running the development server and opening the following URL:

GET http://localhost:8080/api/hello

Response:

    {
        "message": "Hello World!"
    }

Built With

  • Node.js - JavaScript runtime for building server-side applications.
  • Express - Fast, unopinionated, minimalist web framework for Node.js.
  • TypeScript - Strongly typed programming language that builds on JavaScript.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors