From 47ef90de26dc90b3d862bae7d3dcd3b74935e900 Mon Sep 17 00:00:00 2001 From: Krouty Date: Wed, 5 Jan 2022 21:23:08 +0100 Subject: [PATCH] replace request with node-fetch #37 fixing request is deprecated #37 --- node_helper.js | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/node_helper.js b/node_helper.js index ffa2478..d62ee5d 100644 --- a/node_helper.js +++ b/node_helper.js @@ -9,7 +9,7 @@ */ var NodeHelper = require('node_helper'); -var request = require('request'); +const fetch = require('node-fetch'); module.exports = NodeHelper.create({ start: function () { @@ -54,16 +54,15 @@ module.exports = NodeHelper.create({ var warnurl = 'https://maps.dwd.de/geoserver/dwd/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=dwd:Warnungen_Gemeinden&outputFormat=application%2Fjson&CQL_FILTER=' + regionFilter + severityStr; // console.error(warnurl); - var requests = 2; - + var requests = 2; + //get name - request({ - url: nameurl, + fetch(nameurl, { method: 'GET' - }, function (error, response, body) { - var result = JSON.parse(body); - if (result.totalFeatures == 1) { - communityData = result.features[0]; + }).then(res => res.json() + ).then(json => { + if (json.totalFeatures == 1) { + communityData = json.features[0]; } if (--requests == 0) { if (region.reg) @@ -72,18 +71,15 @@ module.exports = NodeHelper.create({ callback(self, warningData, region.cellid, communityData); } }); - + //get warnings - request({ - url: warnurl, + fetch(warnurl, { method: 'GET' - }, function (error, response, body) { - - var result = JSON.parse(body); - - if (result.totalFeatures > 0) { - for (var i = 0; i < result.totalFeatures; i++) { - warningData.push(result.features[i]); + }).then(res => res.json() + ).then(json => { + if (json.totalFeatures > 0) { + for (var i = 0; i < json.totalFeatures; i++) { + warningData.push(json.features[i]); } } if (--requests == 0) {