The robust backend API powering Nerdtalks, a modern community forum platform. This RESTful API handles user authentication, content management, payment processing, and administrative operations for the Nerdtalks community.
- Production URL: https://nerdtalks-server.vercel.app/
- Frontend Application: https://nerdtalks-sh.web.app/
- Node.js - JavaScript runtime environment
- Express.js - Fast, unopinionated web framework
- MongoDB - NoSQL database for flexible data storage
- Firebase Admin SDK - Server-side authentication verification
- JWT Tokens - Secure token-based authentication
- CORS - Cross-origin resource sharing middleware
- Stripe - Secure payment gateway for membership subscriptions
- Vercel - Serverless deployment platform
- users - User profiles, roles, and badges
- posts - Forum posts with voting and metadata
- comments - Post comments and replies
- tags - Content categorization system
- announcements - Admin announcements and notifications
- reports - Content moderation and reporting system
- Client sends Firebase ID token in Authorization header
- Server verifies token using Firebase Admin SDK
- Decoded user information attached to request object
- Protected routes accessible with valid authentication
All protected routes require Authorization: Bearer <firebase-token> header.
GET /users/:uid # Get user by Firebase UID
GET /users # Get all users (admin, paginated)
POST /users # Create/update user profile
PATCH /users/:uid/badges # Add badge to user
PATCH /users/:id/make-admin # Promote user to admin
GET /posts # Get all posts (paginated, filterable)
GET /post/:id # Get single post by ID
GET /posts/user/:authorId # Get user's posts (dashboard)
POST /posts # Create new post
PATCH /posts/:postId/vote # Vote on post (up/down)
DELETE /posts/:id # Delete post
GET /comments/:postId # Get comments for a post
GET /comments/post/:postId # Get paginated comments (dashboard)
POST /comments # Create new comment
DELETE /comments/:id # Delete comment (admin)
GET /reports # Get all reports (admin, paginated)
POST /reports/comment # Report a comment
PATCH /reports/:id/status # Update report status (admin)
DELETE /reports/:id/delete # Delete report (admin)
GET /tags # Get all available tags
POST /tags # Create new tag (admin)
GET /announcements # Get all announcements
POST /announcements # Create announcement (admin)
GET /admin/stats # Get platform statistics (admin)
POST /create-payment-intent # Create Stripe payment intent
- Node.js (v14 or higher)
- MongoDB database
- Firebase project with Admin SDK
- Stripe account for payments
-
Clone the repository
git clone <repository-url> cd nerdtalks-server
-
Install dependencies
npm install
-
Environment Configuration Create a
.envfile in the root directory:# Database MONGODB_URI=your_mongodb_connection_string # Firebase Admin FB_SECRET=your_firebase_admin_private_key # Payment Processing STRIPE_SECRET_KEY=your_stripe_secret_key # Server Configuration PORT=3000
-
Firebase Admin Setup
- Create a
decrypter.jsfile that exports your Firebase service account credentials - Ensure proper security for Firebase private keys
- Create a
-
Start the development server
npm start
-
Test the API
npm run dev # Should return: "Nerds are talking"
{
"express": "Web application framework",
"mongodb": "MongoDB driver for Node.js",
"firebase-admin": "Firebase Admin SDK",
"stripe": "Stripe payment processing",
"cors": "Cross-origin resource sharing",
"dotenv": "Environment variable management"
}- Token Verification: Every protected route validates Firebase ID tokens
- Role-Based Access: Admin-only endpoints with proper authorization
- Request Validation: Input sanitization and validation on all endpoints
- Environment Variables: Sensitive credentials stored securely
- CORS Configuration: Controlled cross-origin access
- Input Validation: Comprehensive request body validation
- Configurable Limits: Support for custom page sizes
- Metadata: Total counts, page information, and navigation flags
- Performance: Efficient database queries with skip/limit
- Tag-based Filtering: Filter posts by content categories
- Search Functionality: Text search across user names and emails
- Sorting Options: Sort by popularity, date, or relevance
- Dual Voting: Support for both upvotes and downvotes
- Vote Switching: Users can change their vote type
- Vote Removal: Users can remove their votes
- Popularity Calculation: Dynamic popularity scoring
- Report System: Users can report inappropriate content
- Admin Workflow: Comprehensive tools for handling reports
- Status Tracking: Report lifecycle management
- Bulk Operations: Efficient batch processing for moderation
# Install Vercel CLI
npm i -g vercel
# Deploy to Vercel
vercel --prodConfigure the following environment variables in your Vercel dashboard:
MONGODB_URIFB_SECRETSTRIPE_SECRET_KEY
- Database Indexing: Optimized queries with proper indexing
- Aggregation Pipelines: Efficient data processing for complex operations
- Connection Pooling: MongoDB connection optimization
- Caching Strategy: Reduced database load with smart caching
# Run development server
npm run dev
# Test specific endpoints
npm run testAll API responses follow a consistent format:
{
"message": "Success message",
"data": "Response data",
"pagination": "Pagination info (when applicable)"
}Comprehensive error handling with appropriate HTTP status codes:
400- Bad Request (validation errors)401- Unauthorized (authentication required)403- Forbidden (insufficient permissions)404- Not Found (resource doesn't exist)500- Internal Server Error (server issues)
We welcome contributions! Please ensure all contributions include:
- Proper error handling
- Input validation
- Authentication middleware where needed
- Consistent code formatting
Maksudur Rahman
- GitHub: @code-shams
- LinkedIn: code-shams
- Portfolio: https://code-shams.vercel.app
Powering the Nerdtalks community with robust, scalable backend infrastructure