On Wed, Dec 26, 2012 at 7:31 PM, Rodrigo Fonseca <[email protected]>wrote:
> I've to create a server just to read a file??? > No, of course not. But your original code indicated that you want to read a file and then serve it. That's what Jose's code does - it reads the file (in one line of code), and then creates a server that serves the contents of that file each time a new request is made. > I'm getting trouble with this, because always when i call a URL i create a > server, because i put this inside of s function: > No, the server is created once, and the (anonymous) function that was passed to createServer is called each time a request is handled. That function sends back the contents of the file that was read earlier. It might be a good idea for you to work through one or two tutorials on Node, so that you get a clearer picture of how it all works. You'll find pointers to several of those in the archives of this list. Those at http://www.nodetuts.com/ and http://www.nodebeginner.org/ seem to be fairly frequently referenced here. -- Martin Cooper > http.createServer(function(request, response) { response.writeHeader(200, > {"Content-Type": "text/html"}); response.write(html); response.end(); > }).listen(8000); > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
