Electron-Svelte-Recipe-Planner/package/NimRecipe/debug.js
2021-12-16 00:55:59 -05:00

32 lines
No EOL
1.1 KiB
JavaScript

const net = require("net");
const fs = require("fs")
//so this is a script which is used to make sure the server is working.
async function updateJson(){
var query = {
//sending 0 is how you send the entire DB
//send query : index to get much less info
query: "fetch", ints: 0}
return new Promise(resolve => {
var socket = new net.Socket();
var send30 = JSON.stringify(query)
console.log(send30)
socket.setEncoding('utf8');
socket.connect(12345, "127.0.0.1", function () {
socket.write(send30 + "\r\L" + "\n")
var dataa = []
//when data is ready to be sent...
socket.on('data', function (data) {
dataa.push(data)
})
socket.on('end', function () {
//the data isn't encoded with anything cool so we don't need to process it
resolve(dataa.join(''))
})
})
})
}
updateJson().then(data => {
//writes it for parsing or inspection, whatever floats your boat, weirdo
fs.writeFileSync("debug.json",data)
})