Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
require('dotenv').config();
import dotenv from 'dotenv';
dotenv.config();
import fetch from 'node-fetch';

// Print out value of API key stored in .env file
console.log(process.env.API_KEY)
async function getImage(query) {
const endpoint = `https://api.giphy.com/v1/gifs/search?api_key=${process.env.API_KEY}&q=${query}&limit=25&offset=0&rating=g&lang=en`;

try {
const response = await fetch(endpoint);
const data = await response.json();

console.log(data.data[0].images.original)

const gifUrl = data.data[0].images.original.url;
console.log("GIF URL:", gifUrl);
return gifUrl;
} catch (error) {
console.error("Error fetching GIF:", error);
return null;
}
}

getImage("cats");
62 changes: 43 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "Who doesn't love a good gif? ![](https://media.giphy.com/media/cJMlR1SsCSkUjVY3iK/giphy.gif)",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -18,6 +19,7 @@
},
"homepage": "https://github.com/MultiverseLearningProducts/Async-Giphy#readme",
"dependencies": {
"dotenv": "^16.0.3"
"dotenv": "^16.0.3",
"node-fetch": "^3.3.2"
}
}