This is a boilerplate project for a Node.js application using TypeScript, Express, and PostgreSQL.
- TypeScript: Write clean and robust code using TypeScript, a statically typed superset of JavaScript.
- Express: Fast, unopinionated, minimalist web framework for Node.js.
- PostgreSQL: Powerful, open-source object-relational database system.
- Sequelize ORM: Easy-to-use ORM for interacting with PostgreSQL.
- Environment Configuration: Manage environment variables using dotenv.
- ESLint: Ensure code quality with ESLint.
- Prettier: Maintain code style consistency using Prettier.
- Swagger: Automatically generate API documentation.
- Nodemon: Monitor changes in your source and automatically restart the server.
- Ts-node: Run TypeScript code directly without precompiling.
- API Error Handling: Centralized error handling mechanism.
- Project Structure: Organized project structure for scalability and maintainability.
Before you begin, ensure you have the following installed:
- Node.js (version 18.19.0)
- Yarn
- PostgreSQL
git clone https://github.com/your-username/nodejs-typescript-express-boilerplate.git
cd nodejs-typescript-express-boilerplate
yarn install
Create a .env file in the root directory and add the following environment variables:
DB_USER=your_username
DB_HOST=your_host
DB_NAME=your_database
DB_PASSWORD=your_password
DB_PORT=5432
PORT=3000
npx sequelize-cli init
Update the config/config.json file with your database configuration
An example: User model with firstName, lastName, and email attributes.
npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string
npx sequelize-cli db:migrate
npx sequelize-cli db:migrate:undo
npx sequelize-cli db:migrate:undo:all
yarn dev
The server will start on the port specified in your .env file (default is 3000).
You can access the Swagger documentation to explore and test the API endpoints.
Swagger UI: http://localhost:3000/api-docs