How to transfer data received by nodejs/request to another file

Asked 2 years ago, Updated 2 years ago, 36 views

// api.js

let express = require("express");

let request = require("request");

const $url = "https://api2.sktelecom.com/weather/current/hourly";

let $lat   = 37.539079;

let $lon   = 126.990669;
const $key = "751d8762-5bcf-42b2-9121-f4bbeb68976d";

let $api = $url + "?lat=" + $lat + "&lon=" + $lon + "&appkey=" + $key;

request($api, function (error, response, body) {

    let json = JSON.parse(body);
    let weather = json.weather.hourly;

}

Put the data received as a request in weather

Please tell me how to transfer to another file called app.js

node.js

2022-09-21 21:29

1 Answers

Let's modularize api.js App.js to api.I think there is a way to use callback when calling the js module.

In the current structure, it seems difficult to deliver the value to app.js.


2022-09-21 21:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.