Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send IP address from frontend using ReactJS to server NodeJS

Tags:

reactjs

ip

client

At present I am using WEBRTC for getting IP address from client side.

But I have issues with browsers like Internet Explorer etc. I don't want to hit other third party servers for getting IP.

Is there a way to get IP address from ReactJS without hitting third party servers.

like image 435
Kodanda Rama Durgarao Poluri Avatar asked Jan 07 '18 14:01

Kodanda Rama Durgarao Poluri


People also ask

How do you send data from frontend react to backend node JS?

Thus, to connect a React frontend with a NodeJS backend, we need to utilize the useEffect hook and the async function fetch() . useEffect will allow us to only run our fetch request once (when the component gets mounted) which will avoid slowing down our app.

How do I connect to a react JS server?

listen(PORT, console. log(`Server started on port ${PORT}`)); Frontend setup: First, we have to create React app and run your app by writing the below command. Output: Now go to http://localhost:3000/ in your browser, you will see the following output.

CAN node JS and react JS work together?

For hosting a react application, NodeJS is the best platform. Node JS can be used for server-side development and React JS for front-end development reducing the need for multiple languages and frameworks.


2 Answers

You can make a request to your own nodejs server and reply with the IP address. that way 3rd party servers wont be involved.

like image 62
Sairam Avatar answered Oct 17 '22 23:10

Sairam


Check sample express code below and use

app.get('/getIP', getClientIP);

Sample code

like image 44
scetiner Avatar answered Oct 17 '22 23:10

scetiner