Use Node.js Server (for Login) if App is run using Android Device

So, I’m following this tutorial about how to make a log in and sign up function in an Ionic 2 app using angular-jwt.

As you may know, to log in or sign up, we need a server where we can do a validation to check if the entry data are correct or not. In this case, the author use Node.js server where the server is hosted in the localhost.

This works perfectly if the app is run using ionic serve. But what if I want it to run it in an Android device using “ionic run android” command? The answer is it won’t work. The app just throw an object event error.

Anybody has a say on this? Please help!

I don’t know your code but you may did not change the server address from “localhost” to the IP Address of your mac/windows machine.
you also need to be in the same network if you develop locally.

if this is not the case please provide some code snippets and error logs so we can help you :slight_smile:

I’m sorry, but I still use the same code from that tutorial.

So here it is the repo https://github.com/auth0-blog/ionic2-auth

You can see in the page file named Profile.ts
He writes
LOGIN_URL: string = “http://localhost:3001/sessions/create”;
SIGNUP_URL: string = “http://localhost:3001/users”;

I’m still new to Ionic and Javascript. So, don’t really understand how do I change that localhost address to IP address of my mac. Please tell me how to write it correctly.

Also, about that /sessions/create and /users, you can see it in the server folder, it’s in the file user-routes.js

So localhost is the same as the ip address of your mac.
[alt] click on the wlan symbol on your mac on the top right to see your ip address.
it may be something like 10.0.0.5

if your mobile phone and your mac are in the same network you can communicate via the ip addresses.