1

I am learning Node now, and I am a little perplexed regarding the virtual server component of it. What I would like to understand is, where does Node reside when it's serving web pages?

For example learning it now, I of course have Node downloaded on my machine locally. And I am learning about how to create the virtual server via code like the following:

var http = require("http");

http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(8888);

When it's time to take whatever I end up developing in Node live to the web, do I download Node to the server that is hosting my site? And then I guess if I do that, is the following going to take place:

"Node.js contains a built-in asynchronous I/O library for file, socket, and HTTP communication, which allows applications to act as a web server without software such as Apache or IIS." WikiPedia Article on Node

So I guess,...the files, that will be my application, once living in the server hosting my site, with Node.js installed, will act as a web server without software such as Apache or IIS?

So I am confused about this server creation process and where Node.js lives when it serves web pages.

Regarding the code, that I understand. That's just JavaScript.

I'd appreciate the clarification. Thanks, Chris Mazzochi

Chris Mazzochi
  • 179
  • 1
  • 15
  • You can run Node.JS as [a (simple) web server](http://stackoverflow.com/q/6084360/2970947). – Elliott Frisch Aug 19 '14 at 02:02
  • 1
    Node.js *is* the server software (like Apache or IIS). – Thilo Aug 19 '14 at 02:03
  • it doesn't live anywhere but RAM. node.js doesn't serve web pages, it serves the result of calling javascript expressions. it's up to you to correlate those expressions with resources in a path, if that's what you need. i think express makes it more LAMPy/RESTy. – dandavis Aug 19 '14 at 02:04
  • Thanks for taking the time. I appreciate it. – Chris Mazzochi Aug 19 '14 at 20:59

2 Answers2

0

I would add this as a comment, but don't have the reputation to do that yet :\

To start your webserver, you would just run the point-of-entry script, which would then just run as a process. I think you would want to setup a daemon / service to launch the script for you, though.

--edit--

That script in your question is just that - a script. You need to run it for it to actually start working with something like node simpleServer.js. If you were wanting to actually host something other than a website that returned Hello World, like I said above, you would want a daemon / service to auto-run that script for you.

So I am confused about . . . where Node.js lives when it serves web pages.

It lives in computer's memory.

0

When you have developed your app in Node and want to host it on a web server you need to install it.

If you going cloud based (Example Heroku) it has Node installed already and you just need to define the procfile thats it.

If you want to map it to your domain then you can map your dns with the app you creating on the cloud.

V31
  • 7,626
  • 3
  • 26
  • 44