Quickstart Guide
This guide will help you set up and run the Cognit Backend API on your local machine.Prerequisites
Before you begin, ensure you have the following installed:- Node.js (v14 or higher recommended)
- PostgreSQL (v12 or higher)
- npm (comes with Node.js)
Make sure PostgreSQL is running and you have access to create databases.
Installation
Install dependencies
Install all required packages using npm:This will install Express.js, TypeScript, Sequelize, JWT, and all other dependencies.
Configure environment variables
Create a
.env file in the root directory with the following variables:.env
Set up the database
Create a PostgreSQL database for the application:The application will automatically create the required tables on first run using Sequelize’s
sync method.Your First API Call
Once the server is running, you can make your first API request to retrieve all games.Example Response
Production Build
To build and run the application in production:Database Models
The API includes the following main models:User Model
username- User’s display nameemail- Unique email addresspassword- Hashed password (bcrypt)token- 6-digit verification tokenpoints- Gamification pointsconfirmed- Email confirmation status
Games Model
title- Game nameexplanation- Game descriptionpoints_reward- Points awarded on completioncategoryId- Reference to game category
Security Features
Cognit Backend includes several security features out of the box:- Helmet.js - Sets secure HTTP headers
- CORS - Configured for specific origins
- Rate Limiting - 5 requests per minute on auth endpoints
- JWT Authentication - Secure token-based auth
- Password Hashing - Bcrypt with salt rounds
- Input Validation - Express-validator on all inputs
Rate limiting is set to 5 requests per 60 seconds on authentication endpoints. You can adjust this in
src/config/limiter.ts.Next Steps
Now that you have the API running:Explore Authentication
Learn how to implement user registration and login
API Reference
View all available endpoints and their parameters
Games Management
Discover how to manage games and categories
User System
Understand the user and points system
Troubleshooting
Database Connection Failed
If you see “Database connection failed” in the console:- Verify PostgreSQL is running:
pg_isready - Check your
DATABASE_URLin.env - Ensure the database exists
- Verify user credentials and permissions
Port Already in Use
If port 3005 is already in use, change thePORT variable in your .env file:
Rate Limit Errors
If you’re hitting rate limits during development, you can temporarily adjust the limiter insrc/config/limiter.ts or disable it on specific routes.