This Express TypeScript Starter is designed to be a comprehensive template for building high-quality web applications using Express with TypeScript.
- Type Safety: TypeScript provides static type checking, which helps catch errors early in the development process.
- Improved Developer Experience: Features like auto-completion and code navigation enhance productivity and code quality.
- Simplified Routing: Easily manage routes through a file-based routing system, which organizes endpoints within the file structure.
- Automatic Route Discovery: New routes are automatically recognized without manual registration, streamlining the development workflow.
An example of file-based routing can be seen below:
// src/routes/user.ts import { Router } from 'express'; const router = Router(); // GET request for http://localhost:5000/user router.get('/', function (req, res) { res.send('User List'); }); // POST request for http://localhost:5000/user/create router.post('/create', function (req, res) { res.send('User created'); }); export default router;Thats it! No more integration.
- Code Quality Enforcement: Husky integrates Git hooks that ensure code standards are met before commits and pushes (e.g., linting and testing).
- Automated Workflows: Set up pre-commit and pre-push workflows to automate tasks like code formatting and validation.
Start with
npm run prepare
- Consistent Code Style: Enforce a consistent coding style across the project, making the codebase easier to understand and maintain.
- Catch Common Errors: Identify and fix common coding mistakes before they become problematic.
- Automatic Formatting:
Prettierformats code consistently, ensuring a uniform code style throughout the project. - Integration with Editors: Integrate
Prettierwith your code editor for on-the-fly formatting as you write code.
- Development Efficiency:
Nodemonis configured to automatically restart the server during development when code changes are detected. - Environment Variables:
Dotenv-cliintegration for managing environment variables in development and production setups. - Production Ready: The starter is configured for deployment on platforms like Render.com and Vercel, with predefined build and start commands.
- Initialize Project: You can quickly bootstrap a new Express TypeScript project using the
npxcommand.
npx sohanemon@latest express-ts my-express-appnpx sohanemon@latest express-ts my-express-app --yarnnpx sohanemon@latest express-ts my-express-app --pnpmnpx sohanemon@latest express-ts my-express-app --bun - Clone the repository.
- Install dependencies with
npm install. - Start the development server with
npm run dev.
npm start: Launches the server.npm run build: Compiles TypeScript to JavaScript in thedistdirectory.npm run dev: Starts the development server with nodemon.npm run lint: RunsESLintto check for linting errors.npm run format: Checks for formatting issues withPrettier.npm run format:write: Formats code withPrettier.
Follow the instructions in docs/render.md for deploying your application on Render.com.
Feel free to fork and use this starter template for your projects. Contributions to enhance this template are welcome.
This project is open-sourced under the MIT License.