Node. JS is a set of JavaScript toolkit used to write high-performance network servers. A series of changes started from this. Specifically, node. js assumes that you are running Linux or Mac OS X in the POSIX environment. If you are running Windows, install mingw to obtain a POSIX-like environment. In node, HTTP is the first priority. Node is optimized to create an HTTP server, so most examples and libraries you can see on the Internet are concentrated on the Web (HTTP framework, template library, etc ).
First, download the installation from the http://nodejs.org. My version is 0.6.6. The installation is very simple. The next step is the next step.
My installation directory is c: \ Program Files (x86) \ nodejs.
1. helloworld
Create a new file "Hello. js" in the nodejs installation directory and click "One Line ".Code Copy codeThe Code is as follows: console. Log ('hello, nodejs .');
Go to the command line console, go to the nodejs directory, and tap node hello. js.
The console outputs "Hello, nodejs ."
Ii. Web helloworld
Create an HTTP. js file in the nodejs installation directory. The Code is as follows:
Copy code The Code is as follows: var HTTP = require ("HTTP ");
HTTP. createserver (function (request, response ){
Response. writehead (200, {"Content-Type": "text/html "});
Response. Write ("Hello world! ");
Response. End ();
}). Listen (8000 );
Start the service in the command line and tap node HTTP. js
Open the address bar of the browser and enter http: // localhost: 8000/. The Hello world is displayed! It is successful.