Open ChandN162 opened 4 days ago
const express = require('express'); const bodyParser = require('body-parser'); const app = express();
app.use(bodyParser.json()); app.use(express.static('public')); // Serve frontend files
// Fake user database let users = { user1: { points: 0 } };
// Endpoint to handle task completion app.post('/complete-task', (req, res) => { const { taskId } = req.body;
if (!taskId) return res.status(400).send({ message: 'Task ID is required' });
// Add points based on task
const pointsEarned = taskId === 1 ? 10 : 20;
users.user1.points += pointsEarned;
res.send({ message: `Task completed! You earned ${pointsEarned} points.` });
});
// Endpoint to get user points app.get('/points', (req, res) => { res.send({ points: users.user1.points }); });
// Start the server
const PORT = 3000;
app.listen(PORT, () => console.log(Server running on http://localhost:${PORT}
));
npm install mongoose
const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/earning-app', { useNewUrlParser: true, useUnifiedTopology: true });
const UserSchema = new mongoose.Schema({ name: String, points: Number });
const User = mongoose.model('User', UserSchema);
npm install paypal-rest-sdk
const paypal = require('paypal-rest-sdk');
paypal.configure({ mode: 'sandbox', // or 'live' client_id: 'your-client-id', client_secret: 'your-client-secret' });
<!DOCTYPE html>
Welcome to the Earning Website
Complete tasks below to earn rewards:
Task 1: Watch a video
Task 2: Fill a survey