Ad

NodeJS - To Perform Request, Define Both Url And Callback

- 1 answer

So I have been starting to get Nodejs to work and it seems like it is not going my way. I have been trying to learn using cloudscraper This code to be exact and whenever I run it with command node test.js it always return a error of

#!/usr/bin/env node
/* eslint-disable promise/always-return */

var cloudscraper = require('cloudscraper');
var fs = require('fs');

cloudscraper.get({ uri: 'https://subscene.com/content/images/logo.gif', encoding: null })
  .then(function (bufferAsBody) {
    fs.writeFileSync('./test.gif', bufferAsBody);
  })
  .catch(console.error);

Error: To perform request, define both url and callback
    at performRequest (C:\Users\node_modules\cloudscraper\index.js:84:11)
    at Object.cloudscraper.get (C:\Users\node_modules\cloudscraper\index.js:17:3)
    at Object.<anonymous> (C:\Users\test.js:7:14)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)

At this point I dont know what I am doing wrong and here I am asking what I am doing wrong?

EDIT:

Im leaving this thread but I fixed it by removing the node_modules and reinstalled from the beginning!

Ad

Answer

Did you try a minimalist version?

var cloudscraper = require('cloudscraper');

cloudscraper.get('https://subscene.com/content/images/logo.gif')
  .then(function (bufferAsBody) {
    console.log('success');
  })
  .catch(console.error);
Ad
source: stackoverflow.com
Ad