I'm new to node/express. I have a simple express app with one post route ('/'). Given a list of GitHub users names, it should return information about those developers.
For example, if I post
{ "developers": ["JohnSmith", "JaneDoe"] }
It should return
[
{
"bio": "Software Engineer at Google",
"name": "John Smith"
},
{
"bio": "Product Manager, Microsoft",
"name": "Jane Doe"
}
]
This is what I have so far
const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json());
app.post('/', function(req, res, next) {
try {
let results = req.body.developers.map(async d => {
return await axios.get(`https://api.github.com/users/${d}`);
});
let out = results.map(r => ({ name: r.data.name, bio: r.data.bio }));
return res.send(out);
} catch {
next(err);
}
});
app.use((err, req, res, next) => {
res.send("There was an error");
})
app.listen(3000, function(){
console.log("Server started on port 3000!");
});
When I try this in a tool like Insomnia, I keep getting There was an error
.