184 lines
4.5 KiB
Markdown
184 lines
4.5 KiB
Markdown
# Local Development Setup Guide
|
|
|
|
This guide will help you set up the Vaishnavi Creation backend for local development without Docker.
|
|
|
|
## Prerequisites
|
|
|
|
Make sure you have the following installed and running:
|
|
|
|
1. **Node.js 18+** ✅ (You have v22.14.0)
|
|
2. **PostgreSQL 15+** - Make sure it's running
|
|
3. **MongoDB 7+** - Make sure it's running
|
|
4. **Redis 7+** (Optional) - For caching and background jobs
|
|
|
|
## Step 1: Configure Environment Variables
|
|
|
|
1. Copy the environment template:
|
|
```bash
|
|
cp .env.example .env
|
|
```
|
|
|
|
2. Edit the `.env` file with your database credentials:
|
|
|
|
**For PostgreSQL**, update the DATABASE_URL:
|
|
```env
|
|
# Replace with your actual PostgreSQL credentials
|
|
DATABASE_URL="postgresql://username:password@localhost:5432/vaishnavi_db?schema=public"
|
|
```
|
|
|
|
Common PostgreSQL configurations:
|
|
- **Default user**: `postgres`
|
|
- **Default password**: `postgres` (or whatever you set)
|
|
- **Default port**: `5432`
|
|
- **Database name**: `vaishnavi_db` (we'll create this)
|
|
|
|
**For MongoDB**, update the MONGODB_URI:
|
|
```env
|
|
# Usually this is fine for local MongoDB
|
|
MONGODB_URI="mongodb://localhost:27017/vaishnavi_products"
|
|
```
|
|
|
|
**For Redis** (Optional):
|
|
```env
|
|
# Comment this out if you don't have Redis installed
|
|
REDIS_URL="redis://localhost:6379"
|
|
```
|
|
|
|
## Step 2: Create PostgreSQL Database
|
|
|
|
Connect to PostgreSQL and create the database:
|
|
|
|
```sql
|
|
-- Connect to PostgreSQL (replace with your credentials)
|
|
psql -U postgres
|
|
|
|
-- Create the database
|
|
CREATE DATABASE vaishnavi_db;
|
|
|
|
-- Exit psql
|
|
\q
|
|
```
|
|
|
|
**Windows Users**: If you have PostgreSQL installed via installer, you might need to use pgAdmin or the command prompt with full path.
|
|
|
|
## Step 3: Run the Setup Script
|
|
|
|
```bash
|
|
npm run setup
|
|
```
|
|
|
|
This script will:
|
|
- ✅ Check Node.js version
|
|
- ✅ Install dependencies
|
|
- ✅ Generate Prisma client
|
|
- ✅ Create database schema
|
|
- ✅ Seed the database with sample data
|
|
|
|
## Step 4: Start Development Server
|
|
|
|
```bash
|
|
npm run dev
|
|
```
|
|
|
|
The API will be available at `http://localhost:3000`
|
|
|
|
## Troubleshooting
|
|
|
|
### PostgreSQL Connection Issues
|
|
|
|
1. **Make sure PostgreSQL is running**:
|
|
- **Windows**: Check Services or start PostgreSQL service
|
|
- **Linux/Mac**: `sudo systemctl start postgresql` or `brew services start postgresql`
|
|
|
|
2. **Check your connection string**:
|
|
```env
|
|
# Format: postgresql://username:password@host:port/database
|
|
DATABASE_URL="postgresql://postgres:yourpassword@localhost:5432/vaishnavi_db?schema=public"
|
|
```
|
|
|
|
3. **Test connection manually**:
|
|
```bash
|
|
# Test if PostgreSQL is accessible
|
|
psql -U postgres -h localhost -p 5432 -c "SELECT version();"
|
|
```
|
|
|
|
### MongoDB Connection Issues
|
|
|
|
1. **Make sure MongoDB is running**:
|
|
- **Windows**: Check Services or start MongoDB service
|
|
- **Linux**: `sudo systemctl start mongod`
|
|
- **Mac**: `brew services start mongodb-community`
|
|
|
|
2. **Test MongoDB connection**:
|
|
```bash
|
|
# Connect to MongoDB
|
|
mongosh
|
|
# or
|
|
mongo
|
|
```
|
|
|
|
### Redis Connection Issues (Optional)
|
|
|
|
If you don't have Redis installed or don't want to use it:
|
|
|
|
1. Comment out the Redis URL in your `.env` file:
|
|
```env
|
|
# REDIS_URL="redis://localhost:6379"
|
|
```
|
|
|
|
2. The application will work without Redis, but caching and background jobs won't be available.
|
|
|
|
## Manual Setup (Alternative)
|
|
|
|
If the setup script doesn't work, you can run the commands manually:
|
|
|
|
```bash
|
|
# Install dependencies
|
|
npm install
|
|
|
|
# Generate Prisma client
|
|
npx prisma generate
|
|
|
|
# Create database schema
|
|
npx prisma db push
|
|
|
|
# Seed database
|
|
npm run db:seed
|
|
|
|
# Start development server
|
|
npm run dev
|
|
```
|
|
|
|
## Verification
|
|
|
|
Once everything is set up, you can verify by:
|
|
|
|
1. **Health Check**: Visit `http://localhost:3000/health`
|
|
2. **API Root**: Visit `http://localhost:3000/`
|
|
3. **Database Studio**: Run `npm run db:studio` to view your data
|
|
|
|
## Default Users
|
|
|
|
After seeding, you'll have these test users:
|
|
|
|
- **Admin**: `admin@vaishnavi.com` / `admin123`
|
|
- **Customer**: `customer@example.com` / `customer123`
|
|
|
|
## Next Steps
|
|
|
|
1. Test the API endpoints using Postman or curl
|
|
2. Set up your frontend application
|
|
3. Configure AWS S3 for file uploads (optional)
|
|
4. Set up email services for notifications (optional)
|
|
|
|
## Getting Help
|
|
|
|
If you encounter issues:
|
|
|
|
1. Check the logs in your terminal
|
|
2. Verify all services are running
|
|
3. Double-check your `.env` configuration
|
|
4. Make sure you have the correct database permissions
|
|
|
|
Happy coding! 🚀
|