Accessing localhost from outside

后端 未结 2 434
小蘑菇
小蘑菇 2020-12-12 00:21

I have looked for some way to run node.js server on my android device. I found some good article describing it : https://medium.freecodecamp.com/building-a-node-js-applicat

相关标签:
2条回答
  • 2020-12-12 01:00

    Try running ifconfig in the terminal and look at the wlan0 entry for the inet addr: field to find your ip on your wifi.

    0 讨论(0)
  • 2020-12-12 01:22

    You can access your localhost android running your Node, if your TelCo allow, following the below steps. Note: this is only valid when your mobile is connected using your phone data-plan (2-3-4-5... G data), and not when it's using a wi-fi connection. To be clear: your app, on your mobile, only serves content, by the below method, if this mobile is not using wi-fi data.

    1 - setup an account in a dynamic dns provider website (good plans are always paid). There you will configure an URL like http://muhlinin.mydyndns.com which will be pointing to a dynamic IP number;

    2 - install the respective dynamic dns app into your mobile, this app will forward your current IP number to your dynamic dns account, something that assures every request to http://muhlinin.mydyndns.com always will find your mobile to respond to that request, whatever IP your mobile has at the request time;

    3 - on your android, running (for example) Termux and Node, make your .js server script listen to a not default port (cause the default, 80, may be closed by your TelCo), for example, 8000, on the dynamic url you got following itens 1 and 2 showed above. Something like this: http://muhlinin.mydyndns.com:8000

    Of course, if your mobile turns off, or the respective dyn dns app is closed or not started, or your Node server is closed or not started, every call to http://muhlinin.mydyndns.com:8000 will result in error. So, in order to have everything working, you have to have the previous 3 steps done correctly and all opened and started on your mobile server:

    1 - dyn dns app;

    2 - Node.js runtime;

    3 - your serverscript.js (which you will start by doing a simple 'node serverscript.js' on Termux.

    0 讨论(0)
提交回复
热议问题