-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
29 lines (26 loc) · 926 Bytes
/
seed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require('dotenv').config();
require('./config/database');
const fetch = require('node-fetch');
const ROOT_URL = 'https://quizapi.io/api/v1/questions';
const key = process.env.API_KEY;
const Question = require('./models/question');
async function getQuestions(req, res, next) {
const data = await fetch(`${ROOT_URL}?apiKey=${key}`);
const quizData = await data.json();
for (question of quizData) {
const exists = await Question.exists({apiId:question.id})
if (!exists) {
await Question.create({
apiId: question.id,
question: question.question,
choices: question.answers,
answer: question.correct_answers,
tag: question.tags[0].name,
category: question.category,
difficulty: question.difficulty
})
}
}
console.log('Finished!');
}
getQuestions();