How do you get JSON data using $.getJSON with Node.js

后端 未结 1 400
刺人心
刺人心 2021-01-29 01:34

I\'m new to Node.js. I already have a frontend javascript script that uses an API and gets weather data like so:

function getTextWeatherUsingStation(theStation){         


        
1条回答
  •  囚心锁ツ
    2021-01-29 02:23

    $.getJSON is jQuery's function for front to make http requests.

    You are on backend now. So things will be little different here. This is not how you make requests from backend instead should consider using one of the native modules to make http requests which is http module and you use it like

     http.request(Options, function(res) { ...
    

    Or if you want to use something like getJson here is get-json library that you can use like

    getJSON('URL', function(error, response){..
    

    Ofcourse you'll have to install it first with npm install get-json

    then use in your project like var getJSON = require('get-json')

    0 讨论(0)
提交回复
热议问题