Beginner Node,js Primer (1) ======== Build the first node server

Source: Internet
Author: User
Tags node server

Nothing to do, study a node. js, although there are a lot of resources on the Internet tutorial, but it is not as good as the memory of their own handwriting to the deep.

Create a node server The first step: Download the node. JS installation and configure environment variables.

Create node Server second step: Find the root directory of node. js, drive letter: \nodejs\node_modules This is the root directory of node. js.

Create a node server step three: Create a new JS file, such as Server.js, placed under the Node_modules directory.

Create a node server fourth step: Edit the Server.js file, the code is as follows

//introducing the Require modulevarHTTP = require (' http ');//setting up HTTP requestsHttp.createserver (function(Request, response) {//Send HTTP Header    //HTTP Status value: 200:ok    //content Type: Text/plainResponse.writehead (200,{' content-type ': ' Text/plain '}); //Send response data: "Hello World"Response.End ("Hello world\n");}). Listen (8888);//The terminal printing information is as follows:Console.log (' Server running at http://127.0.0.1:8888/');

This creates a node server, which is now ready to be tested.

Test phase:

1. Open the cmd command line, enter the drive letter: \nodejs\node_modules, run the command: node server.js, do this step to see the effect of

, you can see the effect by copying the http://127.0.0.1:8888/into the browser.

After the next node implementation for the last couple of years and then pasted up ...

Beginner Node,js Primer (1) ======== Build the first node server

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.