- Save cards in external json file

This commit is contained in:
Administrator 2021-06-08 12:25:28 +02:00
parent 9e054ddd91
commit 23cb7ee8d7
2 changed files with 74 additions and 35 deletions

View File

@ -1,43 +1,11 @@
let express = require('express');
let fs = require('fs');
let app = express();
let server = require('http').createServer(app);
let {Server} = require("socket.io");
let io = new Server(server);
let cards = [
{
id: 1,
diffuculty: 1,
question: "Was?",
answers: [
{answer_a: "A", status: false},
{answer_b: "B", status: true},
{answer_c: "C", status: false},
{answer_d: "D", status: false},
],
},
{
id: 2,
diffuculty: 2,
question: "Wie?",
answers: [
{answer_a: "A", status: false},
{answer_b: "B", status: true},
{answer_c: "C", status: false},
{answer_d: "D", status: false},
]
},
{
id: 3,
diffuculty: 3,
question: "Wo?",
answers: [
{answer_a: "A", status: false},
{answer_b: "B", status: true},
{answer_c: "C", status: false},
{answer_d: "D", status: false},
]
}
];
let {raw_data} = fs.readFileSync(__dirname + '/../data/cards.json');
let cards = JSON.parse(raw_data);
let port = 5000;
server.listen(port, function () {

71
data/cards.json Normal file
View File

@ -0,0 +1,71 @@
[
{
"id": 1,
"diffuculty": 1,
"question": "Was?",
"answers": [
{
"answer_a": "A",
"status": false
},
{
"answer_b": "B",
"status": true
},
{
"answer_c": "C",
"status": false
},
{
"answer_d": "D",
"status": false
}
]
},
{
"id": 2,
"diffuculty": 2,
"question": "Wie?",
"answers": [
{
"answer_a": "A",
"status": false
},
{
"answer_b": "B",
"status": true
},
{
"answer_c": "C",
"status": false
},
{
"answer_d": "D",
"status": false
}
]
},
{
"id": 3,
"diffuculty": 3,
"question": "Wo?",
"answers": [
{
"answer_a": "A",
"status": false
},
{
"answer_b": "B",
"status": true
},
{
"answer_c": "C",
"status": false
},
{
"answer_d": "D",
"status": false
}
]
}
]