Skip to main content

Getting Started

Follow these steps to start using the NestJS Starter Kit.

Prerequisites

  • Node.js (v18 or later recommended)
  • npm or yarn
  • PostgreSQL database (optional - can run without database)

Creating a New Project

The easiest way to get started is by using our CLI:

npx nestjs-starter-kit my-project

This will create a new project in the my-project directory with all the starter kit features pre-configured.

Manual Installation

Alternatively, you can clone the repository:

  1. Clone the repository:
git clone https://github.com/latreon/nest-starter-kit.git
cd nest-starter-kit
  1. Install dependencies:
npm install
  1. Configure Environment Variables:

Create a .env file in the root of the project based on .env.example:

# Application
NODE_ENV=development
PORT=3000
DATABASE_ENABLED=false # Set to true if you want to use a database

# Database Configuration (required only if DATABASE_ENABLED=true)
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=your_postgres_username
DB_PASSWORD=your_postgres_password
DB_NAME=nest_starter

# JWT Configuration
JWT_SECRET=your_secret_key
JWT_EXPIRATION=1d
JWT_REFRESH_SECRET=your_refresh_secret_key
JWT_REFRESH_EXPIRATION=7d

# Throttling
THROTTLE_TTL=60
THROTTLE_LIMIT=10

# Swagger
SWAGGER_ENABLED=true
  1. Running Without a Database

You can run the application without a database by setting:

DATABASE_ENABLED=false

In this mode, the application will use in-memory data with a mock user:

This is useful for quick testing and development. Note that in this mode, most write operations (create/update/delete) will be disabled.

  1. Running With a Database (Optional)

If you want to use a database:

  • Set DATABASE_ENABLED=true in your .env file
  • Create a PostgreSQL database with the name specified in your .env file:
psql -U postgres
CREATE DATABASE nest_starter;
\q
  • Run database migrations:
npm run migration:run
  1. Starting the Application

For development:

npm run start:dev

For production:

npm run build
npm run start:prod

The API server should now be running at http://localhost:3000.

When running in development mode, you can access the Swagger documentation at:

http://localhost:3000/api/docs

Project Structure

src/
├── app/ # Application core
│ ├── common/ # Common utilities and helpers
│ └── modules/ # Feature modules
│ ├── auth/ # Authentication module
│ ├── user/ # User management module
│ └── shared/ # Shared services and utilities
├── config/ # Configuration settings
├── database/ # Database setup and migrations
└── main.ts # Application entry point

API Endpoints

Authentication Endpoints

MethodEndpointDescriptionProtected
POST/auth/loginUser loginNo
POST/auth/logoutLogout userYes
POST/auth/refreshRefresh access tokenNo
GET/auth/envGet authentication environmentNo
POST/auth/2fa/enableEnable two-factor authenticationYes
POST/auth/2fa/validateValidate 2FA codeYes

User Endpoints

MethodEndpointDescriptionProtected
POST/usersCreate a new userYes
GET/usersGet all usersYes
GET/users/{id}Get user by IDYes
PUT/users/{id}Update userYes
DELETE/users/{id}Delete userYes
GET/users/profileGet current user profileYes
PUT/users/profileUpdate current user profileYes

Next Steps

After setting up your project, check out the following sections to learn more about the features and how to use them: