Load document from URL

The following code snippet shows how to convert a document from an URL:

const fetch = require('node-fetch');

async function fetchUrl(url) {
    try {
        const response = await fetch(url);
        
        if (!response.ok) {
            throw new Error(`URL fetch error: ${response.statusText}`);
        }

        const stream = response.body;
        return stream;
    } catch (error) {
        throw new Error(error);
    }
}

const url = 'https://github.com/groupdocs-conversion/GroupDocs.Conversion-for-Node.js-via-Java/blob/master/Examples/Resources/SampleFiles/sample.docx?raw=true'

try {
    const stream = await fetchUrl(url)
    const converter = new groupdocs.conversion.Converter(stream);
    const convertOptions = new groupdocs.conversion.PdfConvertOptions();
    converter.convert('loadDocumentFromUrl.pdf', convertOptions);

}catch(e){
    throw new Error(e);
}