Beginner node. JS console output and listen for HTTP requests

Source: Internet
Author: User

for the node. JS installation It is easy to find the corresponding computer version directly to install it, so far as you know, without any configuration.
once installed, you will have node. js Command prompt running the program directly.
then you can create the first applet, create a file directly in a folder, such as First.js, and then open, write in: Console.log ("Hello js"); So the first program is done. Open node. js command prompt into the folder, enternode First.js will find the word "Hello JS" printed on the console.
Write the second program below: a basic HTTP server. Look at the code first:Analysis:The First line: request (require) node. js's own HTTP module, and assign it to an HTTP variable, and the variable name can of course be arbitrary. Second line: We invoke the function Createserver () provided by the HTTP module. This function returns an object that has a method called Listen, which has a numeric parameter that specifies the port number that the HTTP server listens on. In the Createserver () method, it is a way to output some values to the browser. The entire program runs like this: Start the server first and enter the node Httpserver.js command in node. js command Prompt to start the server. In the second step, enter in the browser address bar: http://loaclhost:8000 (the port number you specified). You will then see the Hello World print normally in the browser.         

Beginner node. JS console output and listen for HTTP requests

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.