JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
18 days ago3 views
👨‍💻Programming

Untitled Page

// Maps the required task API endpoints to their controller actions.
const express = require('express');
const { getTasks, createTask, updateTask, deleteTask } = require('../controllers/taskController');

const router = express.Router();
router.route('/').get(getTasks).post(createTask);
router.route('/:id').put(updateTask).patch(updateTask).delete(deleteTask);

module.exports = router;
// Replaces the task collection with the provided TaskFlow sample dataset.
require('dotenv').config();
const mongoose = require('mongoose');
const connectDB = require('../config/db');
const Task = require('../models/Task');
const tasks = require('../data/taskflow-data.json');

const seed = async () => {
  try {
    await connectDB();
    await Task.deleteMany({});
    await Task.insertMany(tasks);
    console.log(`Seeded ${tasks.length} tasks`);
    await mongoose.disconnect();
  } catch (error) {
    console.error(`Seed failed: ${error.message}`);
    process.exitCode = 1;
    await mongoose.disconnect();
  }
};

seed();
# Copy this file to .env when configuring the TaskFlow API.
PORT=5001
MONGODB_URI=mongodb://127.0.0.1:27017/taskflow
// Configures the Express application, middleware, health check, and API routes.
const express = require('express');
const cors = require('cors');
const taskRoutes = require('./routes/taskRoutes');

const app = express();
app.use(cors());
app.use(express.json());
app.get('/api/health', (req, res) => res.json({ status: 'ok' }));
app.use('/api/tasks', taskRoutes);
app.use((error, req, res, next) => {
  if (res.headersSent) return next(error);
  const status = error.name === 'ValidationError' ? 400 : 500;
  return res.status(status).json({ message: error.message });
});

module.exports = app;
// Loads configuration, connects MongoDB, and starts the TaskFlow HTTP server.
require('dotenv').config();
const connectDB = require('./config/db');
const app = require('./app');

const port = process.env.PORT || 5000;
connectDB()
  .then(() => app.listen(port, () => console.log(`API running on port ${port}`)))
  .catch((error) => {
    console.error(`MongoDB connection failed: ${error.message}`);
    process.exit(1);
  });
← Back to timeline