5

Is it possible to use an unpkg.com url in my nodejs project?

I have a project setup to use nodejs https to get the url and it works but I am not sure how or if its possible yet to use that in my nodejs project like we do with a regular installed npm package.

const https = require('https');
const url = 'https://unpkg.com/@tensorflow-models/speech-commands@0.3.3/dist/speech-commands.min.js';

Then I need to use it here:

async function app() {
    https.get(url, (res) => {
        const statusCode = res.statusCode;

        if (statusCode != 200) console.error(`Error ${statusCode}: ${res.statusMessage} ${url}.`);
        else console.log('Success');
    });
    recognizer = speechCommands.create('BROWSER_FFT');
    await recognizer.ensureModelLoaded();
    predictWord();
};

The response comes back with success but I ultimately need to use the package via that url. I want to be able to substitute the instance speechCommands with the res from unpkg.com. Is this possible? The reason I am trying this is because when I use the npm package I get a fetch undefined error and since this package is rather new, there isn't an issues section setup in their repo to ask.

user11317802
  • 79
  • 11

0 Answers0