Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: options.uri is a required argument

I'm using node.js v4.6.0 and the latest versions of express, request and body-parser, yet i'm getting an error code which I can't fix, any ideas?

Here's my code:

var express = require('express');
var request = require('request');
var bodyparser = require('body-parser');

var app = express();
app.use(bodyparser.urlencoded({extended: true}))

    var webhook = process.env.DISCORD_WEBHOOK;

app.get('/', (req, res) => {
    res.sendFile(__dirname + '/index.html');
});

app.post('/webhook', (req, res) =>{
    request({
        method: 'POST',
        url: webhook,
        json: {
            "content": req.body.msg,
            "username": "Potato"
        }
    });

    res.redirect("/");
});

app.listen(80, () => {
    console.log("Server Started!");
});

and the error message i'm receiving:

Error: options.uri is a required argument
   at Request.init (C:\Users\kingn\node_modules\request\request.js:233:31)
   at new Request (C:\Users\kingn\node_modules\request\request.js:129:8)
   at request (C:\Users\kingn\node_modules\request\index.js:55:10)
   at C:\Users\kingn\index.js:15:5
   at Layer.handle [as handle_request]     (C:\Users\kingn\node_modules\express\lib\router\layer.js:95:5)
   at next (C:\Users\kingn\node_modules\express\lib\router\route.js:131:13)
   at Route.dispatch     (C:\Users\kingn\node_modules\express\lib\router\route.js:112:3)
   at Layer.handle [as handle_request] (C:\Users\kingn\node_modules\express\lib\router\layer.js:95:5)
   at C:\Users\kingn\node_modules\express\lib\router\index.js:277:22
   at Function.process_params (C:\Users\kingn\node_modules\express\lib\router\index.js:330:12)

Any fixes?

like image 628
LoneWolf Avatar asked Oct 15 '16 20:10

LoneWolf


1 Answers

You need to provide URL information while making a request, check to see that correct URL is getting assigned to your webhook variable, i.e

var webhook = process.env.DISCORD_WEBHOOK; //webhook should be assigned a valid URL for example: 'https://stackoverflow.com/'

try console.log(webhook);

to find out URL for which you are making a request.

like image 115
Anand K Sant Avatar answered Nov 06 '22 04:11

Anand K Sant