System Requirements
Before getting started, ensure you have the following installed:- Node.js (v16 or higher recommended)
- npm (comes with Node.js)
- PostgreSQL (v12 or higher)
- Git (for version control)
Installing Dependencies
The Cognit Backend uses the following key dependencies:Production Dependencies
Install npm packages
- express (v4.21.1) - Web framework
- sequelize-typescript (v2.1.6) - ORM for PostgreSQL
- pg (v8.13.1) - PostgreSQL client
- helmet (v8.0.0) - Security headers
- cors (v2.8.5) - Cross-origin resource sharing
- express-rate-limit (v7.4.1) - Rate limiting
- jsonwebtoken (v9.0.2) - JWT authentication
- bcrypt (v5.1.1) - Password hashing
- nodemailer (v6.9.16) - Email functionality
- express-validator (v7.2.0) - Input validation
PostgreSQL Database Setup
Install PostgreSQL
Environment Variables Configuration
Create a.env file in the root directory with the following variables:
For Gmail, you’ll need to generate an App Password instead of using your regular password.
Environment Variables Reference
| Variable | Description | Required | Default |
|---|---|---|---|
PORT | Port number for the server | No | 3005 |
DATABASE_URL | PostgreSQL connection string | Yes | - |
JWT_SECRET | Secret key for JWT token signing | Yes | - |
EMAIL_HOST | SMTP server hostname | Yes | - |
EMAIL_PORT | SMTP server port | Yes | - |
EMAIL_USER | Email account username | Yes | - |
EMAIL_PASS | Email account password | Yes | - |
FRONTEND_URL | Frontend application URL | Yes | - |
Database Initialization
The application uses Sequelize with TypeScript models. Database tables are automatically created on first run.Automatic schema sync
When you start the development server, Sequelize will automatically:
- Connect to the database (src/server.ts:10-21)
- Synchronize the schema with
db.sync({ alter: true })(src/server.ts:13-14) - Create or alter tables based on your models
Running in Development Mode
Start the development server
nodemon to watch for file changes and automatically restart the server.Testing the Installation
Test that everything is working:Next Steps
Configuration
Learn about configuring CORS, rate limiting, and email settings
API Reference
Explore available API endpoints