A complete backend API for a Digital News Platform similar to Times of India, built with Node.js, Express.js, and SQLite.
- Authentication & Authorization: JWT-based auth with social login (Google)
- News Management: Articles, categories, authors, and content management
- User Engagement: Comments, bookmarks, reading history, and polls
- Personalization: AI-powered news feed algorithm and recommendations
- Subscription System: Multiple subscription tiers with premium content
- Real-time Features: Breaking news and push notifications
- Search & Discovery: Advanced search with filters and trending calculation
- Moderation: Comment moderation with profanity filtering
- Analytics: View tracking, engagement metrics, and user behavior analysis
- Node.js (v14 or higher)
- npm or yarn
- SQLite3
-
Clone the repository
git clone <repository-url> cd Digital-News-Platfrom
-
Install dependencies
npm install
-
Environment setup
cp env.example .env
Edit
.envfile with your configuration:PORT=3000 NODE_ENV=development JWT_SECRET=your-super-secret-jwt-key DB_PATH=./database/news_platform.db
-
Database setup
# Create database and tables npm run db:migrate # Seed with sample data npm run db:seed
-
Start the server
# Development mode npm run dev # Production mode npm start
The API will be available at http://localhost:3000
POST /api/auth/register
Content-Type: application/json
{
"email": "user@example.com",
"username": "username",
"password": "password123",
"firstName": "John",
"lastName": "Doe"
}POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}POST /api/auth/social-login
Content-Type: application/json
{
"idToken": "google-id-token"
}GET /api/news/feed?page=1&limit=10
Authorization: Bearer <token>GET /api/news/trending?timeWindow=24h&limit=10GET /api/news/breakingGET /api/articles?page=1&limit=10&category=uuid&author=uuidGET /api/articles/:idPOST /api/articles
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "Article Title",
"content": "Article content...",
"categoryId": "category-uuid",
"summary": "Article summary",
"tags": ["tag1", "tag2"]
}PUT /api/articles/:id
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "Updated Title",
"content": "Updated content..."
}POST /api/articles/:id/viewGET /api/articles/:id/commentsPOST /api/comments
Authorization: Bearer <token>
Content-Type: application/json
{
"articleId": "article-uuid",
"content": "Comment content",
"parentId": "parent-comment-uuid" // Optional for replies
}POST /api/comments/:id/vote
Authorization: Bearer <token>
Content-Type: application/json
{
"vote": "up" // or "down"
}GET /api/categoriesGET /api/categories/:id/articles?page=1&limit=10GET /api/bookmarks
Authorization: Bearer <token>POST /api/bookmarks
Authorization: Bearer <token>
Content-Type: application/json
{
"articleId": "article-uuid",
"collectionId": "collection-uuid", // Optional
"notes": "Personal notes"
}DELETE /api/bookmarks/:id
Authorization: Bearer <token>GET /api/authors/:idGET /api/authors/:id/articles?page=1&limit=10POST /api/authors/:id/follow
Authorization: Bearer <token>GET /api/users/preferences
Authorization: Bearer <token>PUT /api/users/preferences
Authorization: Bearer <token>
Content-Type: application/json
{
"categories": ["category-uuid1", "category-uuid2"],
"authors": ["author-uuid1"],
"language": "en",
"emailNotifications": true,
"pushNotifications": true
}GET /api/users/history?page=1&limit=10
Authorization: Bearer <token>GET /api/subscriptions/plansPOST /api/subscriptions/subscribe
Authorization: Bearer <token>
Content-Type: application/json
{
"planId": "plan-uuid",
"paymentMethod": "stripe",
"autoRenew": true
}GET /api/subscriptions/status
Authorization: Bearer <token>GET /api/polls/active?limit=10POST /api/polls/:id/vote
Authorization: Bearer <token>
Content-Type: application/json
{
"optionIndex": 0
}PUT /api/notifications/settings
Authorization: Bearer <token>
Content-Type: application/json
{
"emailNotifications": true,
"pushNotifications": true,
"smsNotifications": false
}POST /api/notifications/register-device
Authorization: Bearer <token>
Content-Type: application/json
{
"deviceToken": "fcm-device-token",
"platform": "ios" // or "android"
}The application uses SQLite with the following main entities:
- Users: User accounts and preferences
- Authors: Journalists and content creators
- Categories: News categories and subcategories
- Articles: News articles with metadata
- Comments: User comments with moderation
- Bookmarks: Saved articles and collections
- ReadingHistory: User reading behavior tracking
- Subscriptions: Subscription plans and user subscriptions
- BreakingNews: Urgent news alerts
- Polls: Interactive polls and surveys
- MediaGallery: Photos and videos with metadata
- Notifications: User notifications and settings
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3000 |
NODE_ENV |
Environment | development |
DB_PATH |
SQLite database path | ./database/news_platform.db |
JWT_SECRET |
JWT signing secret | Required |
JWT_EXPIRES_IN |
JWT expiration time | 7d |
GOOGLE_CLIENT_ID |
Google OAuth client ID | Optional |
RATE_LIMIT_WINDOW_MS |
Rate limiting window | 900000 (15 min) |
RATE_LIMIT_MAX_REQUESTS |
Max requests per window | 100 |
The application uses Sequelize ORM with SQLite. Database files are stored in the database/ directory.
-
Environment Configuration
NODE_ENV=production JWT_SECRET=your-production-secret DB_PATH=/path/to/production/database.db
-
Database Migration
npm run db:migrate
-
Start Production Server
npm start
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["npm", "start"]# Run tests
npm test
# Run tests with coverage
npm run test:coverageAll API responses follow a consistent format:
{
"data": {...},
"message": "Success message",
"status": 200
}{
"error": "Error message",
"message": "Detailed error description",
"status": 400,
"timestamp": "2024-01-01T00:00:00.000Z",
"path": "/api/endpoint"
}- JWT-based authentication
- Password hashing with bcrypt
- Rate limiting on API endpoints
- Input validation and sanitization
- SQL injection prevention
- XSS protection with helmet
- CORS configuration
- Database indexing for fast queries
- Pagination for large datasets
- Caching strategies (Redis ready)
- Optimized database queries
- Rate limiting to prevent abuse
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License.
For support and questions:
- Create an issue in the repository
- Contact the development team
- Check the documentation
- Initial release
- Complete news platform backend
- Authentication and authorization
- Article management system
- User engagement features
- Subscription system
- Search and personalization
If you are on Windows, run setup commands one at a time (not with &&):
cp env.example .env
npm install
npm run db:migrate
npm run db:seed
npm run dev
- Only one server instance running (no EADDRINUSE error on port 3000)
-
.envis NOT committed (onlyenv.exampleis in git) -
node_modules/is NOT committed (should be in.gitignore) - All endpoints tested with the provided Postman collection
- README is up to date
- Database is seeded and API is working at http://localhost:3000