How to locally save data returned from an API to a JSON file?

Asked

Viewed 528 times

-1

I’m making a requisition HTTP to receive data, after receiving it, I need to store it locally in a file JSON.

  • How can I create and transfer this data to the archive .json?

Requisition HTTP :

const request = require('request');

request('url', (error, response, body) => {
    const parsedWeather = JSON.parse(body);
});

1 answer

0

The browser cannot manipulate anything from your operating system, all that is available for use is what the browser already allows.

If you want to persistently manipulate data in files such as JSON, a server should be used! For you an option would be the NodeJS, since you use the Javascript, using the NodeJS you can manipulate the files with the library fs and use the CRUD.

But don’t be discouraged, if you don’t want to use a server for some reason (backend), you can use other options like:

  • 1) Local storage with LocalStorage and/or SessionStorage.
  • 2) Use a BaaS (backend as a service), which has a database NoSQL in real time, an example since it uses Javascript is the Firebase!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.