nodeguy/website/docs/guides/networking.md

1.2 KiB

sidebar_label title
Networking Networking

Many apps need to load resources from a remote URL. You may want to make a POST request to a REST API, or you may need to fetch a chunk of static content from another server.

Remember that NodeGui apps do not run in a browser and hence do not have access to browser apis. NodeGui app is essentially a Node.js app.

And in a typical Node.js application you would use a third party library like axios, node-fetch or frisbee for achieving this functionality.

Using Node Fetch

Node Fetch is a light-weight module that brings window.fetch to Node.js.

An example usage would look like this:

const fetch = require('node-fetch');
async function getData() {
    try {
        let response = await fetch('https://somewebsite.com/some.json');
        let responseJson = await response.json();
        return responseJson.somecontent;
    } catch (error) {
        console.error(error);
    }
}

Take a look at the Node Fetch docs for a full list of properties.