Express TypeScript API
by mhofwell
A blank Express server setup with TypeScript support. It provides a basic structure for building REST APIs with Node.js and TypeScript.
View on GitHub
Last updated: N/A
Express TypeScript API
A blank Express server setup with TypeScript support.
Project Structure
express-typescript-api/
├── src/ # Source files
│ ├── config/ # Configuration files
│ ├── routes/ # API routes
│ └── server.ts # Express application setup
├── dist/ # Compiled JavaScript files
├── .gitignore # Git ignore file
├── package.json # Project metadata and dependencies
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
Prerequisites
- Node.js (v14.x or higher recommended)
- npm (v6.x or higher)
Installation
-
Clone the repository:
git clone <repository-url> cd express-typescript-api
-
Install dependencies:
npm install
Development
To start the development server with hot-reloading:
npm run dev
This will start the server at http://localhost:3000
Building for Production
To compile the TypeScript code to JavaScript:
npm run build
This will create the compiled JavaScript files in the dist
directory.
Running in Production
To run the compiled JavaScript in production:
npm start
Available API Endpoints
GET /
: Returns a welcome messageGET /health
: Health check endpoint
Environment Variables
Create a .env
file in the root directory with the following variables:
NODE_ENV=development
PORT=3000
Adding New Routes
- Create a new route file in the
src/routes
directory - Import and use the route in
src/server.ts
License
ISC