Sprint Challenge - Node.js & Express

Overview

The Sprint Challenge is an opportunity for you to demonstrate your mastery of the learning objectives from this sprint. You will build a complete web API that demonstrates your understanding of Node.js, Express, routing, middleware, and deployment.

Sprint Objectives

In this sprint challenge, you will demonstrate your proficiency in:

  • Node.js Core Features - Using Node.js to create server-side applications
  • Express Framework - Leveraging Express to build RESTful APIs
  • RESTful API Design - Implementing endpoints that follow REST conventions
  • Route Handling - Creating routes for different HTTP methods and resources
  • Middleware - Using both built-in and custom middleware for request processing
  • Error Handling - Implementing proper error handling middleware
  • Data Persistence - Working with data storage (typically using in-memory data for this challenge)
  • API Testing - Testing API endpoints to ensure proper functionality

Challenge Preview

You'll be building a RESTful API for managing a collection of resources. The challenge will typically include:

  1. Setting up an Express server
  2. Creating CRUD (Create, Read, Update, Delete) endpoints
  3. Implementing proper error handling
  4. Using middleware for common tasks
  5. Testing your API with Postman or similar tools
  6. Documenting your API endpoints

The specific domain (users, products, etc.) will be provided in the challenge instructions.

Project Requirements

Code Example - API Structure

Your sprint challenge solution will likely include code similar to this structure:

// server.js
const express = require('express');
const helmet = require('helmet');
const cors = require('cors');

const resourceRouter = require('./resources/resource-router');
const errorHandler = require('./middleware/error-handler');

const server = express();

// Global middleware
server.use(express.json());
server.use(helmet());
server.use(cors());

// Router middleware
server.use('/api/resources', resourceRouter);

// Root endpoint
server.get('/', (req, res) => {
  res.json({ api: 'running' });
});

// Error handling middleware (must be last)
server.use(errorHandler);

module.exports = server;

Your resource router might look like this:

// resource-router.js
const express = require('express');
const router = express.Router();
const ResourceModel = require('../models/resource-model');
const validateResource = require('../middleware/validate-resource');

// GET all resources
router.get('/', async (req, res, next) => {
  try {
    const resources = await ResourceModel.findAll();
    res.status(200).json(resources);
  } catch (err) {
    next(err);
  }
});

// GET resource by id
router.get('/:id', async (req, res, next) => {
  try {
    const resource = await ResourceModel.findById(req.params.id);
    if (resource) {
      res.status(200).json(resource);
    } else {
      res.status(404).json({ message: 'Resource not found' });
    }
  } catch (err) {
    next(err);
  }
});

// POST new resource
router.post('/', validateResource, async (req, res, next) => {
  try {
    const newResource = await ResourceModel.create(req.body);
    res.status(201).json(newResource);
  } catch (err) {
    next(err);
  }
});

// Additional routes for PUT, DELETE, etc.

module.exports = router;

Submission Process

  1. Complete the project according to the requirements
  2. Push your code to GitHub
  3. Submit your repository URL through the Portal
  4. Complete the sprint retrospective survey

Grading Criteria