server.js
1.2 KB
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
30
31
32
33
34
35
36
37
const express = require("express");
const app = express();
const request = require("request");
const convert = require("xml-js");
const fs = require("fs");
// http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/getHoliDeInfo?solYear=2019&solMonth=03&ServiceKey=서비스키
var SERVEICE_KEY =
"qBtJy2Prw8CCnAiijUM7VkuaA9MZozHuiQI4FbEGYdUDPz4%2FM%2FuxegGjNBWK0aWQHvSslVHwIZQwNWh57WgRTA%3D%3D";
var operation = "getHoliDeInfo";
var url =
"http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/" +
operation;
var queryParams = "?" + "solYear" + "=" + "2022";
queryParams += "&" + "solMonth" + "=" + "05";
queryParams += "&" + "ServiceKey" + "=" + SERVEICE_KEY;
app.get("/", function (req, res) {
let requestUrl = url + queryParams;
request.get(requestUrl, (err, res, body) => {
if (err) {
console.log("err => " + err);
} else {
if (res.statusCode == 200) {
var result = body;
var xmlToJson = convert.xml2json(result, { compact: true, spaces: 4 });
console.log(xmlToJson);
fs.writeFileSync("holi.json", xmlToJson);
}
}
});
res.send("OK");
});
const port = 8080;
app.listen(port, () => console.log("Listening on port " + port));