1

So say, you have:

  • A VPS running a Node.js server
  • A web host & domain that's running a website say www.example.com

Is there a way you can have www.example.com connect to the Node.js server and retrieve data from it?

Because I just started messing around with node, and I've looked at over 10 tutorials and read a bunch of implementations of Node.js and in all of their examples they say connect to localhost:8080 or 127.0.0.1:8080. (That would mean my vps would have to host www.example.com (the client) & the node.js (the server) for me to use both??)

But I haven't come across any code/tutorials that allows me to run a JavaScript script to connect to the Node.js server and load in data dynamically from the page I'm at. Thanks.

Here's an example of code I'm looking at. http://tympanus.net/codrops/2012/10/11/real-time-geolocation-service-with-node-js/

Zera42
  • 2,592
  • 1
  • 21
  • 33
  • So, have you tried changing localhost to http://www.example.com:8080 ? – GiveMeAllYourCats Jan 16 '14 at 13:30
  • Example.com and the node.js are hosted on 2 different servers. I'm the client, so I would like to connect to example.com, and dynamically get data from the node.js server. I'm thinking that a way to do this was define the ip/port of the server in a script on the example.com server and have it connect that way, but I'm not quite that familiar with node.js or socket.io yet. I'll keep looking for answers. – Zera42 Jan 16 '14 at 21:04

1 Answers1

1

Yes, you can use any URL to reach a nodeJs server.

Routing a request (to say www.example.com) to a nodeJs server has nothing to do with the nodeJs server. You have to make sure that the routing rules are in place, but that is completely separate to your server.

Update in response to you comment clarification:

Are you trying to make connections:

client -> example.com -> node.js?

If so, and example.com is a standard server, then yes, just make calls to node.js URL, that'll work fine

If you looking for the below flow

    node.js

client/ \ example.com

And if you client is a browser, then you will have to deal with cross-domain issues as discussed here AJAX cross domain call

Community
  • 1
  • 1
brent
  • 1,095
  • 1
  • 11
  • 27