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.