@ssit-hub/mvp-generate-template
Version:
A beautiful CLI tool to quickly generate MVP project templates with modern frameworks and best practices
57 lines (48 loc) • 1.4 kB
text/typescript
import express, { Request, Response } from 'express';
import cors from 'cors';
import helmet from 'helmet';
import apiRoutes from './routes/api';
import errorHandler from './middleware/errorHandler';
const app = express();
const port = process.env.PORT || 3000;
// Middleware
app.use(helmet()); // Security headers
app.use(cors()); // Enable CORS
app.use(express.json()); // Parse JSON bodies
app.use(express.urlencoded({ extended: true })); // Parse URL-encoded bodies
// Routes
app.get('/', (req: Request, res: Response) => {
res.json({
message: 'Welcome to TypeScript Express API!',
version: '1.0.0',
language: 'TypeScript',
endpoints: {
health: '/health',
api: '/api'
}
});
});
app.get('/health', (req: Request, res: Response) => {
res.json({
status: 'OK',
timestamp: new Date().toISOString(),
uptime: process.uptime(),
language: 'TypeScript'
});
});
// API routes
app.use('/api', apiRoutes);
// Error handling middleware
app.use(errorHandler);
// 404 handler
app.use('*', (req: Request, res: Response) => {
res.status(404).json({
error: 'Route not found',
path: req.originalUrl
});
});
app.listen(port, () => {
console.log(`🚀 TypeScript Server is running on port ${port}`);
console.log(`📍 Health check: http://localhost:${port}/health`);
console.log(`🔗 API endpoint: http://localhost:${port}/api`);
});