Node.js is a set of JavaScript toolkits for writing high-performance Web servers, and a series of changes begin. Quite uniquely, Node.js will assume that you are running Linux or Mac OS X in a POSIX environment. If you are under Windows, then you need to install MinGW to get a POSIX-like environment. In node, HTTP is paramount. Node optimizes the creation of HTTP servers, so most of the examples and libraries you see on the Web are focused on the Internet (HTTP frameworks, template libraries, and so on).
First, go to http://nodejs.org to download the installation. My next version is 0.6.6. The installation is simple, the next step is OH.
My installation directory is C:\Program Files (x86) \nodejs.
First, HelloWorld
Create a new file in the Nodejs installation directory hello.js, knocking a line of code inside
Copy Code code as follows:
Console.log (' Hello, Nodejs. ');
Go to the command line console and go to the Nodejs directory to knock node Hello.js
The console outputs "Hello, Nodejs."
Second, the web version of the HelloWorld
Create a new http.js in the Nodejs installation directory with the following code
Copy Code code as follows:
var http = require ("http");
Http.createserver (function (request, response) {
Response.writehead ({"Content-type": "Text/html"});
Response.Write ("Hello world!");
Response.End ();
}). Listen (8000);
Start the service on the command line, knocking node Http.js
Then open the browser address bar input http://localhost:8000/, see the page output Hello world! was successful.