I followed the Hubspot Academy tutorial for APIs to try and get a simple API call up and running, but I ran into a problem that I couldn’t find answers to.
For context, here is my package.json code:
{
"name": "hello_world",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.16.3",
"axios": "^0.17.0"
}
}
Along with my index.js code (api key not included, of course):
const express = require('express');
const axios = require('axios');
const app = express();
const API_KEY = "";
app.get('/contacts', async (req, res) => {
const contacts = `https://api.hubapi.com/contacts/v1/lists/all/contacts/recent?hapikey=${API_KEY}`;
try{
const response = await axios.get(contacts);
const data = response.data;
res.json(data);
}
catch(err){
console.error(err);
}
});
app.listen(3000, () => console.log(`Listening on http://localhost:3000`));
After I run ‘npm start’ and go to localhost:3000, my screen still displays
Cannot GET /
and in my inspect element console, this is what shows.
Could someone help me debug or explain to me what this error is?
Thanks
