Ask coding questions

← Back to all posts
Request not assigning variable

In my repl Skool proj i run

lines 5-9

but when I reference the variable ip at line 34 it returns the error

am i not assigning the variable correctly


In NodeJS, the "IP" variable from request is just limited to the brackets from 7-9, you could go something like

But knowing the nature of nodejs, this might make a race-condition. That is, the request may or may not get solved (in the callback) by the time you run app.listen. I would suggest you run something like:

or you could make your code run with await (that would require you to have async functions in your code tho).


@aimiaf i modified the program with the code you suggusted now to responds with https:/null:[port]


@coder1OO the former or later?

if the former, thats the expected behavior due to the race condition. If the later code snippet, I'll debug it.