Reputation: 91
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-application-on-android-part-1-termux-vim-and-node-js-dfa90c28958f#.xrh3v0du1. I have followed the tutorial and installed linux vm on my device and installed node.js. I have successed to run my node.js script and access it from android browser. But I can't find any way to open this page outside my android device by ip address.
Upvotes: 2
Views: 7750
Reputation: 3149
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.
Upvotes: 3
Reputation: 2917
Try running ifconfig
in the terminal and look at the wlan0
entry for the inet addr:
field to find your ip on your wifi.
Upvotes: 1