Easy to create Nodejs server (1): A simple Nodejs server example _node.js

Source: Internet
Author: User
Tags node server

Let's start by implementing a simple example, Hello world.

It seems that the first verse of every language tutorial will say this, and we are no exception.

First we first create a project directory, the directory can be defined by itself, the directory of this case is e:/nodetest/.

Since we're going to build the server, I named the first file server.js.

Enter the following code inside the Server.js:

Copy Code code as follows:

var http = require ("http");

Http.createserver (function (request, response) {

Response.writehead ({"Content-type": "Text/plain"});

Response.Write ("Hello World");

Response.End ();

}). Listen (8888);

Then we open cmd.

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

Then open the browser to visit http://localhost:8888/, and you'll see a Web page with "Hello World";

In fact, this is a simple work of the server, but simply to do nothing, but it does not matter, follow me step-by-step, I will teach you how to build a fully available server.

In the next section, we'll 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.