Create a node. js server easily (1): A simple node. js server example _ node. js-js tutorial

Source: Internet
Author: User
Tags node server
This article mainly introduces a simple node. js server example. This article implements a simple helloworld example and shows how to run this server, for more information, see the following example: hello world.

It seems that the first section of each language tutorial will talk about this, and we are no exception.

First, create a project directory, which can be defined by yourself. In this case, the directory is e:/nodetest /.

Since we are building a server, I name the first file server. js.

Enter the following code in server. js:

The Code is as follows:


Var http = require ("http ");

Http. createServer (function (request, response ){

Response. writeHead (200, {"Content-Type": "text/plain "});

Response. write ("Hello World ");

Response. end ();

}). Listen (8888 );

Then we open cmd.

Use cd e:/nodetest/to locate the project directory, and then run the node server. js command to run the file;

Then open the browser to access http: // localhost: 8888/, and you will see a webpage with "Hello World;

In fact, this is a simple and workable server, but nothing can be done, but it doesn't matter. Follow me step by step, I will teach you how to build a complete and available server.

In the next section, we will analyze the composition of this Code.

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.