A TypeScript API starter template using Express.js.
- Built with TypeScript for type safety and improved development experience
- Organized directory structure for controllers, middlewares, routes, and services
- Express.js for handling HTTP requests
- Easy to extend and customize
To get a local copy up and running, follow these steps:
-
Clone the repo:
git clone https://github.com/Tomk1111/ts-express-api-template.git
-
Install the dependencies:
npm install
-
Create the .env file using the .env.example as a reference. Edit the values as needed:
cp .env.example .env
-
Start the development server:
npm run dev
Your API will be running at http://localhost:3000. or whichever port you specified in the .env file, e.g:
PORT=3000
src/
├── api/
│ ├── controllers/ # Business logic and request handling
│ ├── middlewares/ # Custom middlewares for request processing
│ │ └── errorHandler.ts # Custom error handler middleware
│ ├── routes/ # Route definitions and management
│ ├── services/ # Business services and data handling
│ └── index.ts # Exports all API routes
├── config/ # Configuration files
│ └── index.ts # Main configuration file
├── loaders/ # Application loaders
│ ├── express.ts # Express app loader
│ ├── logger.ts # Logger loader (winston)
│ └── index.ts # Exports all loaders
├── types/ # Type definitions
│ ├── config.ts # Custom config types
│ └── error.ts # Custom error types
├── app.ts # Entry point of the application
To run the development server, use:
npm run dev
This command will start the server with hot reloading.
To build the application for production, run:
npm run build
Then start the production server:
npm start