Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
547 B
1
Indexable
Never
const express = require("express");
const app = express();
const PORT = 3000;
let alumnos = require('./alumnos.json').alumnos;


app.use(express.json())

app.get('/alumnos/:id', (req, res) => {
    const{id} = req.params
    let alumno = alumnos.find(elemento => elemento.id == parseInt(id))
    if(!alumno) {
        return res.status(404).json({msg:'Alumno no encontrado'})
    } 
    res.status(200).json({msg: "Alumno encontrado", data:alumno})
    
    
})

app.listen(PORT, () => {
    console.log("escuchando!!!");
})