0

Trying to get PHP to send a variable to Node.js, but it changes the variable in my PHP file I have.

exec("node myscript.js --userid=$userid &", $output);

the $userid in my test is 346236693579300867.
In my Nodejs file I have:

var argv = require('minimist')(process.argv.slice(2));
discord.sendMessage("Welcome " + "<@" + argv.userid + ">" );

In Node.js userid = 346236693579300860. It keeps changing the last digit. Even if I do

exec("node myscript.js --userid=346236693579300867 &", $output);

The output is still 346236693579300860.

What am I doing wrong?
Am new to Node.js and PHP so am still learning.
Cheers

Federico Grandi
  • 6,785
  • 5
  • 30
  • 50
Justin Jones
  • 15
  • 2
  • 9
  • No expert but did you try `--userid="346236693579300867"` – Lawrence Cherone Mar 23 '18 at 23:33
  • Yeah, Have tried that one as well. Does the same thing. Seems to be the length of the number after playing around just then. If I do 3462366935793008, it shows the correct number, as soon as I add the next number "6" onto it. I get 34623669357930090. – Justin Jones Mar 23 '18 at 23:42
  • Is the NodeJS just needed to send that message? You could use a PHP Discord Library to send that message – André Mar 23 '18 at 23:43
  • Something like this: https://github.com/restcord/restcord – André Mar 23 '18 at 23:44
  • Not great with php, which is why Im using nodejs as my bot is coded in it. the php I have is just for a callback. But might have to look into it. Might be the easiest way. – Justin Jones Mar 23 '18 at 23:46
  • I'm just looking at the source of minimist: https://github.com/substack/minimist/blob/master/index.js#L59, it uses Number() javascript method, which will cast it. `console.log(Number('346236693579300867'));` :/ – Lawrence Cherone Mar 23 '18 at 23:49
  • See: https://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript you could work around this by prepending a string to it for example: `--userid="_346236693579300867"`, so the minimist code thinks its a string, then in your node code trim off the `_`. – Lawrence Cherone Mar 24 '18 at 00:05

0 Answers0