Anup Vasudeva
Anup Vasudeva

Reputation: 901

Node.js introduction

Please pardon my ignorance on node.js. I have started reading on node.js and have some perception which might be wrong. So needed it to clarify

  1. When we use createServer() method, does it creates a virtual server. Not sure whether the term "virtual" is appropriate, but it's the best I can describe it :)
  2. I am confused that how should I deploy my application having node.js + other custom js files as a part of it. If I deploy my application in the main server, does that mean I have two servers?

Thanks for bearing with me.

Upvotes: 0

Views: 256

Answers (2)

swapnilsarwe
swapnilsarwe

Reputation: 1300

I will try to answer that:

Q1:

createServer basically creates a process which listens on the specified port for the requests. So yes you can call it as a virtual server which constantly listens for request at the port.

Q2:

Yes you can say that it has now 2 servers

For eg: you server had apache initially which listens to port 80 (you can access it as http://example.com/ it by default looks for port 80)

and then you also start the node service listening on some other port for eg: port 8456 (you can access it as http://example.com:8456/ which will look for port 8456)

So yes you can there are two servers.

EDIT

Q: So what would be the difference if the page is served by the physical server and the virtual server created by node.js?

Physical Server and Node Server are 2 different things and there is no way a single request is going to both the servers.

For eg: I use apache server to host my website running on PHP. It serves all the html contents of my website (which involves connecting to mysql for data). Some of the requests could be:

  1. http://example.com/reports.php
  2. http://example.com/search.php

At the other end I might be using nodejs server for totally another purpose. For eg: I might use it for an API, which returns JSON/XML in return. I can use this API myself for some dynamic contents by making AJAX calls with javascript or simple CURL commands from PHP. Or I might also make this API available to public. Some of the requests could be:

  1. http://example.com:8456/getList?apikey=&param1=&param2=

My choice for NodeJs Server used as an API would be for its ability to handle concurrent request and since its asynchronous for file operations it will be much faster than PHP.

In this case I have a website which is not only working on PHP but its the combination of 2 different technologies (PHP on Apache and Nodejs) and hence 2 servers are totally different running on same server but have there own execution space.

Upvotes: 2

film42
film42

Reputation: 1095

Third Question: So what would be the difference if the page is served by the physical server and the virtual server created by node.js?

If I might add, it's a virtual server in the sense that apache is an virtual http server listening on whatever port. Of course apache had a lot more modules and plugins and configurations to it where as Node's is lighter (kind of like WEBrick for rails), non-blocking and agile for building on. Then again apache is more stable.. in other words, it's a decision of software, both sitting on the server listening to a particular port set by you.

That said there's deployment methods that allow you to place a node application in front of software such as nginx (another server-side software) or HAproxy (load handling with a lot of power), so really it's all up to how you choose to configure it.

Maybe I'm getting to far from your question, but I hope this helps!

Also, You should give the answer to the other guy, he came first ;)

Upvotes: 0

Related Questions