Vai al contenuto principale
e-Disciplinas
  • Disciplinas »
    2026 2025 2024 2023 2022 2021 2020 2019 2018 2017 2016 2015 2014 2013 2012 AACCs/FFLCH Pró-Reitoria de Pós-Graduação Outros
  • Suporte »
    Acesso Perfis Ouvintes Docentes Criação de Disciplinas da USP Documentação HelpDesk e Contato Guia de uso Sobre
  • Italiano ‎(it)‎
    Deutsch ‎(de)‎ English ‎(en)‎ Español - Internacional ‎(es)‎ Français ‎(fr)‎ Italiano ‎(it)‎ Português - Brasil ‎(pt_br)‎
  • Chiudi
    Attiva/disattiva input di ricerca
  • Acessar

SCC0219 - Introdução ao Desenvolvimento Web (2025)

  1. Home
  2. Corsi
  3. 2025
  4. ICMC
  5. SCC
  6. SCC0219-2025
  7. Module 8: Node.js/ExpressJS
  8. Exercise 16: Express Web Servers

Exercise 16: Express Web Servers

Aggregazione dei criteri
Aperto: venerdì, 30 maggio 2025, 08:00
Data limite: venerdì, 30 maggio 2025, 12:00


Activity:
Building a Basic Blog API with Express.js

Upload a JavaScript file named USPnumber1.USPnumber2.js. If you need to upload a file after the deadline use late.USPnumber1.USPnumber2.js

Instructions:

  1. Initialize a new Node.js project and install Express.js.

  2. In your main server file, set up a basic Express.js application. Ensure that your server is listening on a port of your choice.

  3. Create a new JavaScript object to act as your database. This should contain an array of "posts". Each post should be an object with properties for "id", "title", "content", and "author".

  4. Set up a middleware function that logs (console.log) the current date and request method to the console before each route. This will be useful for debugging purposes.

  5. Set up the following routes:

    • GET /posts: This should return a list of all posts in your database object.
    • GET /posts/:id: This should return the post with the specified ID. If no such post exists, return an appropriate error message.
    • POST /posts: This should accept JSON input in the form of a new post, which should include properties for "title", "content", and "author". Add the new post to your database object and return the updated list of posts.
    • PUT /posts/:id: This should accept JSON input in the form of an updated post. Replace the post with the specified ID in your database object and return the updated list of posts.
    • DELETE /posts/:id: This should delete the post with the specified ID from your database object and return the updated list of posts.
  6. Test your application using Insomnia, Postman, or another API testing tool.

Remember: Each route should send a response back to the client and handle any errors appropriately. You should also use middleware to parse incoming JSON.

Tips:

  1. Follow the video course up to Lesson 10 and you will end up with a running web server. In lessons 11 and 12, the code is refactored to be more organized.

  2. Lesson 10 explains the REST actions (GET, PUT, POST, and DELETE) and shows how to test the requests using the Postman tool (install in lesson 3).

  3. After lesson 10, you have a running server that has GET, PUT, and DELETE services.

Good luck! Remember to take your time, think through the problem, and test your code often as you're working.

Annex: Express Example


// Importing the express module
const express = require('express');

// Creating an instance of express to setup the server

const app = express();
// Implementing middleware using the 'use' method. Middleware are functions that have access to the request and response objects,
// and can execute any code or make changes to the request and response objects.
// This particular middleware logs the request method (GET, POST, PUT, DELETE, etc.) and the request URL to the console
// 'next' is a function that, when called, executes the next middleware in the stack.
app.use((req, res, next) => {
    console.log(`Request Method: ${req.method}`);
    console.log(`Request URL: ${req.url}`);
    next();
});

// Setting up a GET route at the path '/'. When a GET request is made to this path, 
// the server sends back the string 'Home Page' as a response.
app.get('/', (req, res) => {
    res.send('Home Page');
});

// Setting up a POST route at the path '/data'. When a POST request is made to this path,
// the server sends back the string 'Data received' as a response.
app.post('/data', (req, res) => {
    res.send('Data received');
});

// Setting up a PUT route at the path '/data'. When a PUT request is made to this path,
// the server sends back the string 'Data updated' as a response.
app.put('/data', (req, res) => {
    res.send('Data updated');
});

// Setting up a DELETE route at the path '/data'. When a DELETE request is made to this path,
// the server sends back the string 'Data deleted' as a response.
app.delete('/data', (req, res) => {
    res.send('Data deleted');
});

// Telling the server to listen for incoming requests on port 3000 and log to the console when it starts successfully
app.listen(3000, () => {
    console.log('Server is listening on port 3000');
});

◄ Quiz 8
Quiz 9 ►

Blocchi

Salta Navigazione
  • Home

    • e-Disciplinas

      • I miei corsi

      • Tag

      • Ricerca

      • PaginaSobre

      • PaginaHelp Desk e Contato

      • PaginaGuia

    • I miei corsi

    • Corsi

      • 2025

        • CENA

        • EACH

        • ECA

        • EE

        • EEFE

        • EEFERP

        • EEL

        • EERP

        • EESC

        • EP

        • ESALQ

        • FAU

        • FCF

        • FCFRP

        • FD

        • FDRP

        • FE

        • FEA

        • FEARP

        • FFCLRP

        • FFLCH

        • FM

        • FMBRU

        • FMRP

        • FMVZ

        • FO

        • FOB

        • FORP

        • FSP

        • FZEA

        • IAG

        • IAU

        • IB

        • ICB

        • ICMC

          • SMA

          • SME

          • 550

          • SSC

          • SCC

            • TCCs do SCC

            • SCC0211-2025

            • SCC5920--2025

            • SCC0124-201-2025

            • SCC0283-201-2025

            • SCC0271-201-2025

            • SCC0230-202-2025

            • SCC5878-2025

            • SCC0233-201-2025

            • SCC0295-201-2025

            • ED - SCC0122 - 2025

            • SCC0634-201-2025

            • SCC0245-201-2025

            • SCC0607-201-2025

            • SCC0220-201-2025

            • LabBD-SCC0641-2025

            • SCC0560-201-2025

            • SCC5836--2025

            • SCC0252-201-2025

            • SCC0219-201-2025

            • SCC0202-2025

            • SCC5977--2025

            • SCC5809--2025

            • SCC5960--2025

            • SCC5959--2025

            • SCC5952--2025

            • SCC0277-201-2025

            • SCC0218-2025

            • SCC0227/SCC0229--2025

            • SCC0505--2025

            • SCC5832--2025

            • SCC0205-202-2025

            • SCC0205-201-2025

            • SCC0502-201-2025

            • SCC0223-201-2025

            • SCC0207-2025

            • SCC0580-201-2025

            • SCC0302-2025

            • SCC5949--2025

            • SCC5982--2025

            • SCC0216-2025

            • SCC0219-2025

              • Introduzione

              • Group Assignment

              • Course Introduction

              • Module 1: HTTP Protocol

              • Module 2: HTML

              • Module 3: CSS

              • Module 4: JavaScript

              • Module 5: DOM & Events

              • Module 6: AJAX Calls

              • Milestone 1

              • Module 7: React or Vue

              • Module 8: Node.js/ExpressJS

                • CompitoExercise 16: Express Web Servers

              • Milestone 2

              • Module 9: NoSQL Databases

              • Final Presentations

              • Final Test

          • EST

          • MAI

          • SMA

        • IEB

        • IEE

        • IF

        • IFQSC

        • IFSC

        • IGc

        • IME

        • IO

        • IP

        • IPEN

        • IQ

        • IQSC

        • IRI

        • HRAC

        • MAC

        • MAE

        • MP

        • MZ

        • RUSP

      • 2026

      • 2024

      • 2023

      • 2022

      • 2021

      • 2020

      • 2019

      • 2018

      • 2017

      • 2016

      • 2015

      • 2014

      • 2013

      • 2012

      • Grupos de Estudos, Pesquisa e Outros

      • PRPG - Pró-Reitoria de Pós-Graduação

      • STI

Blocchi supplementari

Ospite (Login)
Powered by Moodle