Skip to content

adacapo21/nodejs-typescript-express-boilerplate

Repository files navigation

Node.js TypeScript Express Boilerplate

This is a boilerplate project for a Node.js application using TypeScript, Express, and PostgreSQL.

Features

  • 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.

Prerequisites

Before you begin, ensure you have the following installed:

Getting Started

Clone the Repository

git clone https://github.com/your-username/nodejs-typescript-express-boilerplate.git
cd nodejs-typescript-express-boilerplate

Install Dependencies

yarn install

Configure Environment

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

Database Setup

Initialize Sequelize

npx sequelize-cli init

Configure Sequelize

Update the config/config.json file with your database configuration

Generate a Model and Migration

An example: User model with firstName, lastName, and email attributes.

npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string

Run Migrations

npx sequelize-cli db:migrate

Undo Migrations (last migration)

npx sequelize-cli db:migrate:undo

Undo All Migrations

npx sequelize-cli db:migrate:undo:all

Run Project

yarn dev

The server will start on the port specified in your .env file (default is 3000).

API Documentation (Swagger)

You can access the Swagger documentation to explore and test the API endpoints.

Swagger UI: http://localhost:3000/api-docs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published