Can't get the request module to work


Hello, I’m trying to get the request module to work in my Electron app. I have request installed and I have this in my main.js:

var request = require('request')

var url = ''

function request() {
	request(url, function(error, response, body) {
		if (!error && response.statusCode == 200) {

and in my index.html I have a simple button that triggers this function. Once this function is triggered, this is my output in console: C:\Users\ErraticFox\Documents\GitHub\instagram\node_modules\request\index.js:46 Uncaught Error: undefined is not a valid uri or options object.

Why is this?


Just a guess, but perhaps it is because you’re redefining the symbol request?

var request = require('request')

// --- and ---

function request() {

I would guess that the var request is taking precedence over your declaration of function request and so when you call the function request(), it is calling the request module’s version of request with no parameters.

I also updated your title for searchability’s sake.


Wow, I totally wasn’t thinking about that. That’s kind of embarrassing how I didn’t see that.

Thanks, that totally fixed it. :joy: