Beispielsetup für ein Express-Framework Projekt mit Typescript
Find a file
2026-11-11 14:49:19 +01:00
.idea initial commit 2026-11-11 14:49:19 +01:00
dist initial commit 2026-11-11 14:49:19 +01:00
src initial commit 2026-11-11 14:49:19 +01:00
.gitignore initial commit 2026-11-11 14:49:19 +01:00
.nvmrc initial commit 2026-11-11 14:49:19 +01:00
package-lock.json initial commit 2026-11-11 14:49:19 +01:00
package.json initial commit 2026-11-11 14:49:19 +01:00
README.md initial commit 2026-11-11 14:49:19 +01:00
Requirements.md initial commit 2026-11-11 14:49:19 +01:00
tsconfig.json initial commit 2026-11-11 14:49:19 +01:00

Shop Backend

A modular REST API backend built with Express 5, TypeScript, and Node.js 24.


Prerequisites

  • Node.js: v24.x recommended (compatible with Node >= 20)
  • Package Manager: npm (bundled with Node.js)

(Optional: If using nvm, ensure you switch to Node 24 with nvm use 24 or nvm install 24.)


Getting Started

1. Install Dependencies

Install all required project dependencies:

npm install

2. Run in Development Mode

Starts the development server with hot-reloading using tsx watch:

npm run dev

The server will be available at http://localhost:3000.


Available Scripts

Command Description
npm run dev Starts the development server with live reload (src/server.ts).
npm run build Compiles TypeScript into JavaScript (dist/ folder).
npm start Runs the compiled production build (dist/server.js).

Environment Variables

You can configure the server using environment variables:

Variable Default Description
PORT 3000 The port on which the Express server listens.
NODE_ENV development Environment mode (development or production).

Example:

PORT=8080 npm run dev

API Endpoints

All API routes are prefixed with /api.

Health Check

  • GET /api/health — Server status and uptime.

Products

  • GET /api/products — Retrieve all products.
  • GET /api/products/:id — Retrieve a single product by ID.
  • POST /api/products — Create a new product.
    • Headers: Content-Type: application/json
    • Body Example:
      {
        "name": "Mechanical Keyboard",
        "description": "Ergonomic wireless keyboard",
        "price": 129.99,
        "stock": 15
      }
      

Project Structure

shopBackend/
├── dist/                   # Compiled JavaScript output (generated after build)
├── src/
│   ├── controllers/        # Request handling and HTTP responses
│   ├── middlewares/        # Custom Express middlewares (error handling, 404, etc.)
│   ├── routes/             # Route declarations
│   ├── services/           # Business logic and data management
│   ├── types/              # TypeScript interfaces and type declarations
│   ├── app.ts              # Express application configuration
│   └── server.ts           # Server entry point & listener
├── package.json
├── tsconfig.json           # TypeScript configuration
└── README.md