Usage of NodeJS and Ionic 1

Hey people,

I’ve got a question regarding the usage of NodeJS together with my Ionic app. I read some tutorials and blog entries about it but those dont really clear things up for me about how to use those two components together. Understanding the $http or $resource directives is not the problem. I’m struggling connecting my Ionic app with the server I’m running at the same time.

Assuming I start the Ionic app with ionic serve on port 8000, so it is running at localhost:8000 and my NodeJs Server at port 8001, so I can access it at localhost:8001, how do I have to make the API call with the $http or $resource directive in my Ionic controller ? I think I’ve got a general understanding issue about the connection of both frontend and backend components.

I would appreciate it a lot if someone could give me a brief explanation on that :smiley:

Many greetings from Germany
Julian

What exactly don’t you understand?

You make a call to the backend’s URL in Ionic code and work with the result.

Thanks for your reply.

As I said, my server runs under localhost:8001 and my Ionic app under localhost:8000.

Now, for example, I have a route specified in my NodeJS server called /data, I would use it in my Ionic app like:

$http.get("/data")…

The problem here is, that Ionic wants to go to the route localhost:8000/data, but since it is stored in localhost:8001/data, the server can not be adressed.

So my question is:

How do I access localhost:8001/data when Ionic runs under the port 8000 ?

$http.get(“http://localhost:8001/data”)…

1 Like

Wow, I feel some kind of retarded. I tried $http.get(“/data”) and it tried to access localhost:8000/data, using $http.get(“localhost/data”) tried to access localhost:8000/localhost/data. Somehow I forgot about the http:// option.

Sometimes the simplest solutions are the ones which work.

Thank you for opening my eyes mate ! Nice and fast help there.