Skip to main content

Installation Guide

This guide covers everything you need to install, configure, and deploy Connect World in both development and production environments.

System Requirements

Node.js

Version 20 or higher required

MongoDB

Version 5.0 or higher (local or cloud)

Package Manager

npm, yarn, pnpm, or bun

Git

For version control and deployment

Installation Steps

1

Install Node.js

Download and install Node.js 20+ from nodejs.orgVerify installation:
node --version  # Should be v20.0.0 or higher
npm --version
2

Clone Repository

Clone the Connect World repository:
git clone <your-repository-url>
cd connect-world
3

Install Dependencies

Choose your preferred package manager:
npm install
The project uses Next.js 16, React 19, and TypeScript 5. All dependencies are locked in package-lock.json.

Database Setup

Option 1: Local MongoDB

1

Install MongoDB

# Using Homebrew
brew tap mongodb/brew
brew install mongodb-community
2

Start MongoDB Service

brew services start mongodb-community

# Verify it's running
brew services list | grep mongodb
3

Verify Connection

Test MongoDB connection:
mongosh

# You should see:
# Current Mongosh Log ID: ...
# Connecting to: mongodb://127.0.0.1:27017
# Using MongoDB: 7.0.x
Create the database:
use connect-world
db.customers.insertOne({ test: true })
db.customers.deleteOne({ test: true })

Option 2: Docker MongoDB

# Run MongoDB in Docker
docker run -d \
  --name mongodb \
  -p 27017:27017 \
  -v mongodb_data:/data/db \
  mongo:latest
MongoDB in Docker is perfect for development. For production, consider MongoDB Atlas for managed hosting.

Option 3: MongoDB Atlas (Cloud)

1

Create Atlas Account

  1. Go to mongodb.com/cloud/atlas
  2. Sign up for a free account
  3. Create a new cluster (M0 free tier available)
2

Configure Database Access

  1. Navigate to Database Access
  2. Click Add New Database User
  3. Create username and password
  4. Grant Read and write to any database permission
3

Configure Network Access

  1. Navigate to Network Access
  2. Click Add IP Address
  3. For development: Click Allow Access from Anywhere (0.0.0.0/0)
  4. For production: Add your server’s IP address
4

Get Connection String

  1. Click Connect on your cluster
  2. Choose Connect your application
  3. Copy the connection string:
mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/connect-world?retryWrites=true&w=majority

Environment Configuration

Create a .env.local file in the project root with all required variables:

Complete Configuration Template

.env.local
# ============================================
# DATABASE CONFIGURATION (REQUIRED)
# ============================================

# Local MongoDB
MONGDB_URI=mongodb://localhost:27017/connect-world

# Or MongoDB Atlas
# MONGODB_URI=mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/connect-world?retryWrites=true&w=majority

# Or Docker MongoDB with auth
# MONGODB_URI=mongodb://admin:secret@localhost:27017/connect-world?authSource=admin

# ============================================
# STRIPE CONFIGURATION (REQUIRED)
# ============================================

# Get these from: https://dashboard.stripe.com/apikeys

# Secret key (server-side, starts with sk_test_ or sk_live_)
STRIPE_SECRET_KEY=sk_test_51xxxxx

# Publishable key (client-side, starts with pk_test_ or pk_live_)
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51xxxxx

# ============================================
# PAYPAL CONFIGURATION (OPTIONAL)
# ============================================

# Get these from: https://developer.paypal.com/dashboard/

# Client ID (public, used in frontend)
NEXT_PUBLIC_PAYPAL_CLIENT_ID=AYourPayPalClientID123

# Client Secret (private, server-side only)
PAYPAL_CLIENT_SECRET=EYourPayPalClientSecret456

# API Base URL
# Sandbox for testing:
PAYPAL_BASE_URL=https://api-m.sandbox.paypal.com
# Production:
# PAYPAL_BASE_URL=https://api-m.paypal.com

# ============================================
# TMDB API CONFIGURATION (OPTIONAL)
# ============================================

# Get API key from: https://www.themoviedb.org/settings/api
# Required for content catalog display
NEXT_PUBLIC_TMDB_API_KEY=your_tmdb_api_key_here

# ============================================
# ENVIRONMENT
# ============================================

NODE_ENV=development

Environment Variables Reference

Required - MongoDB connection string
From connection.ts
const MONGODB_URI = process.env.MONGODB_URI as string;

if (!MONGODB_URI) {
  throw new Error("Please define MONGODB_URI in .env.local");
}
The connection uses Mongoose with these options:
mongoose.connect(MONGODB_URI, {
  bufferCommands: false,
});
Required - Stripe secret API key (server-side)
From stripe/route.ts
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
Used to:
  • Create payment intents
  • Process card payments
  • Handle 3D Secure authentication
Get from: dashboard.stripe.com/apikeys
Required - Stripe publishable key (client-side)Exposed to browser, safe to commit. Used to initialize Stripe Elements:
import { loadStripe } from '@stripe/stripe-js';
const stripe = await loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY!);
Optional - PayPal client ID (public)
From paypal/create-order/route.ts
const credentials = Buffer.from(
  `${process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID}:${process.env.PAYPAL_CLIENT_SECRET}`
).toString('base64');
Used for PayPal authentication and order creation.
Optional - PayPal client secret (private)Server-side only. Combined with client ID for OAuth token generation:
async function getPayPalAccessToken(): Promise<string> {
  const credentials = Buffer.from(
    `${process.env.NEXT_PUBLIC_PAYPAL_CLIENT_ID}:${process.env.PAYPAL_CLIENT_SECRET}`
  ).toString('base64');
  // ... request access token
}
Optional - PayPal API endpoint
const PAYPAL_BASE = process.env.PAYPAL_BASE_URL ?? "https://api-m.sandbox.paypal.com";
  • Sandbox: https://api-m.sandbox.paypal.com (testing)
  • Production: https://api-m.paypal.com (live payments)
Optional - The Movie Database API key
From tmdbService.ts
const TMDB_API_KEY = process.env.NEXT_PUBLIC_TMDB_API_KEY;
const tmdbClient = axios.create({
  baseURL: BASE_URL,
  params: { api_key: TMDB_API_KEY, language: "es-ES" },
});
Used to fetch:
  • Trending movies and TV shows
  • Now playing movies
  • Top rated series
App works without it, but catalog will be empty.

Payment Provider Setup

Stripe Configuration

1

Create Stripe Account

  1. Sign up at stripe.com
  2. Complete account verification
  3. Enable test mode (toggle in dashboard)
2

Get API Keys

  1. Go to dashboard.stripe.com/apikeys
  2. Copy Publishable key (starts with pk_test_)
  3. Reveal and copy Secret key (starts with sk_test_)
  4. Add both to .env.local
3

Test Payment

Use Stripe test cards:
Card NumberResult
4242 4242 4242 4242Success
4000 0025 0000 3155Requires 3D Secure
4000 0000 0000 9995Card declined
  • Expiry: Any future date
  • CVC: Any 3 digits
  • ZIP: Any 5 digits

PayPal Configuration (Optional)

1

Create Developer Account

  1. Go to developer.paypal.com
  2. Log in or create account
  3. Navigate to Dashboard
2

Create Sandbox App

  1. Click Apps & Credentials
  2. Ensure Sandbox tab is selected
  3. Click Create App
  4. Name your app and click Create App
3

Get Credentials

  1. Copy Client IDNEXT_PUBLIC_PAYPAL_CLIENT_ID
  2. Click Show under Secret → PAYPAL_CLIENT_SECRET
  3. Set PAYPAL_BASE_URL=https://api-m.sandbox.paypal.com
4

Create Test Accounts

  1. Go to Sandbox → Accounts
  2. Create a Business account (merchant)
  3. Create a Personal account (buyer)
  4. Use the personal account email/password for test purchases
For production PayPal, switch to Live credentials and update PAYPAL_BASE_URL to https://api-m.paypal.com

TMDB API Setup (Optional)

1

Create TMDB Account

  1. Sign up at themoviedb.org
  2. Verify your email
  3. Log in to your account
2

Request API Key

  1. Go to Settings → API
  2. Click Request an API Key
  3. Choose Developer (free for non-commercial)
  4. Fill out the application form
  5. Accept terms and submit
3

Copy API Key

  1. Copy your API Key (v3 auth)
  2. Add to .env.local as NEXT_PUBLIC_TMDB_API_KEY
4

Verify Integration

The app uses these TMDB endpoints:
From tmdbService.ts
// Fetch trending content
export async function getTrendingAll(timeWindow: "day" | "week" = "week") {
  const { data } = await tmdbClient.get<TmdbResponse>(
    `/trending/all/${timeWindow}`
  );
  return data.results.slice(0, 10);
}

// Fetch now playing movies
export async function getNowPlayingMovies() {
  const { data } = await tmdbClient.get<TmdbResponse>(
    "/movie/now_playing"
  );
  return data.results.slice(0, 10);
}

// Fetch top rated series
export async function getTopRatedSeries() {
  const { data } = await tmdbClient.get<TmdbResponse>(
    "/tv/top_rated"
  );
  return data.results.slice(0, 5);
}

Running the Application

Development Mode

npm run dev
The app will start at http://localhost:3000
Next.js 16 uses Turbopack by default for faster development builds.

Production Build

1

Build Application

npm run build
This creates an optimized production build in .next/
2

Start Production Server

npm run start

Linting

npm run lint
The project uses ESLint with Next.js configuration:
From eslint.config.mjs
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
  baseDirectory: __dirname,
});

const eslintConfig = [
  ...compat.extends("next/core-web-vitals", "next/typescript"),
];

export default eslintConfig;

Database Schema

Connect World uses two main collections:

Customers Collection

From CustomerModel.ts
export interface CustomerDbDoc extends Document {
  email: string;
  phone: string;
  name: string;
  created_at: Date;
  updated_at: Date;
}

const CustomerSchema = new Schema<CustomerDbDoc>(
  {
    email: { type: String, required: true, unique: true, lowercase: true },
    phone: { type: String, required: true },
    name:  { type: String, required: true },
  },
  {
    timestamps: { createdAt: "created_at", updatedAt: "updated_at" },
  }
);

Orders Collection

From OrderModel.ts
export interface OrderDbDoc extends Document {
  customer_id: string;
  plan_id: string;
  devices: number;
  months: number;
  amount: number;
  payment_method: "stripe" | "paypal";
  payment_receipt_id: string;
  status: "pending" | "completed" | "failed";
  activation_date: Date;
  expiration_date: Date;
  created_at: Date;
  updated_at: Date;
}

const OrderSchema = new Schema<OrderDbDoc>(
  {
    customer_id:        { type: String, required: true, index: true },
    plan_id:            { type: String, required: true },
    devices:            { type: Number, required: true },
    months:             { type: Number, required: true },
    amount:             { type: Number, required: true },
    payment_method:     { type: String, enum: ["stripe", "paypal"], required: true },
    payment_receipt_id: { type: String, required: true, unique: true },
    status:             { type: String, enum: ["pending", "completed", "failed"], default: "pending" },
    activation_date:    { type: Date, required: true },
    expiration_date:    { type: Date, required: true },
  },
  {
    timestamps: { createdAt: "created_at", updatedAt: "updated_at" },
  }
);
The schema uses snake_case for MongoDB fields following common NoSQL conventions, while the application layer uses camelCase.

Security Configuration

Connect World includes comprehensive security headers:
From next.config.ts
const securityHeaders = [
  { key: "X-Frame-Options", value: "DENY" },
  { key: "X-Content-Type-Options", value: "nosniff" },
  { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
  {
    key: "Permissions-Policy",
    value: "camera=(), microphone=(), geolocation=(), payment=(self)",
  },
  { key: "X-XSS-Protection", value: "1; mode=block" },
  {
    key: "Strict-Transport-Security",
    value: "max-age=63072000; includeSubDomains; preload",
  },
  {
    key: "Content-Security-Policy",
    value: [
      "default-src 'self'",
      "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://js.stripe.com https://www.paypal.com https://www.sandbox.paypal.com",
      "style-src 'self' 'unsafe-inline'",
      "img-src 'self' data: blob: https://image.tmdb.org https://www.paypalobjects.com",
      "font-src 'self' data:",
      "connect-src 'self' https://api.stripe.com https://api-m.sandbox.paypal.com https://api-m.paypal.com https://api.themoviedb.org",
      "frame-src https://js.stripe.com https://hooks.stripe.com https://www.paypal.com https://www.sandbox.paypal.com",
    ].join("; "),
  },
];
Adjust CSP headers for your domain before production deployment.

Verification Checklist

Before deploying, verify all components:
1

Database Connection

# Test MongoDB connection
mongosh $MONGODB_URI

# Check collections
use connect-world
show collections
2

Environment Variables

# Verify all required vars are set
node -e "console.log({
  MONGODB_URI: !!process.env.MONGODB_URI,
  STRIPE_SECRET: !!process.env.STRIPE_SECRET_KEY,
  STRIPE_PUBLIC: !!process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
})"
3

Build Success

npm run build
# Should complete without errors
4

API Endpoints

# Start server
npm run dev

# Test health
curl http://localhost:3000

# Test TMDB
curl http://localhost:3000/api/tmdb
5

Payment Test

  1. Navigate to http://localhost:3000
  2. Select a plan
  3. Use Stripe test card: 4242 4242 4242 4242
  4. Complete checkout
  5. Verify order in MongoDB:
mongosh
use connect-world
db.orders.find().pretty()

Troubleshooting

Clear and reinstall dependencies:
rm -rf node_modules package-lock.json
npm install
Change the port:
PORT=3001 npm run dev
Or kill the process using port 3000:
# macOS/Linux
lsof -ti:3000 | xargs kill -9

# Windows
netstat -ano | findstr :3000
taskkill /PID <PID> /F
Check MongoDB is running:
# macOS
brew services list | grep mongodb

# Linux
sudo systemctl status mongod

# Docker
docker ps | grep mongo
Test connection:
mongosh mongodb://localhost:27017
For production, set up Stripe webhooks:
  1. Go to dashboard.stripe.com/webhooks
  2. Add endpoint: https://yourdomain.com/api/webhooks/stripe
  3. Select events: payment_intent.succeeded, payment_intent.payment_failed
  4. Add webhook secret to .env.local

Next Steps

Quick Start

Test your installation with your first subscription

API Reference

Explore available endpoints and data models

Development

Learn the architecture and development workflow

Deployment

Deploy to Vercel, AWS, or your own infrastructure

Build docs developers (and LLMs) love