First download Node.js, then extract to E disk, renamed node, and then Start menu input cmd, cd command to switch to the Nodejs of the Extract directory:
First example: Hello World.
Create the Hello.js file in the node directory and enter it inside:
Copy Code code as follows:
var sys = require ("sys");
Sys.puts ("Hello World");
We then enter the command node Hello.js in the name table and we can see the name console output, Hello World.
Second Example: Hello world2.
Okay, this time we're trying to output Hello World from the viewer. Create the Http.js in the node directory and enter:
Copy Code code as follows:
var sys = require ("sys"),
HTTP = require ("http");
Http.createserver (function (request, response) {
Response.sendheader ({"Content-type": "Text/html"});
Response.Write ("Hello world!");
Response.close ();
}). Listen (8080);
Sys.puts ("Server running at http://localhost:8080/");
Then we enter the command node Http.js in the name console and enter http://localhost:8080/in the browser
A third example: Hello World2.
Node.js provides a buffer class for converting strings of different encodings. There are currently three types of support: ' ASCII ', ' UTF8 ' and ' binary '. For more details here
Copy Code code as follows:
var buffer = require (' buffer '). Buffer,
BUF = new Buffer (256),
Len = Buf.write (' \u00bd + \U00BC = \u00be ', 0);
Console.log (len + "bytes:" + buf.tostring (' UTF8 ', 0, Len));
Fourth Example: Hello world3.
Copy Code code as follows:
Synopsis.js
Synopsis Summary, sketch, outline
var http = require (' http ');
Http.createserver (function (request, response) {
Response.writehead ({' Content-type ': ' Text/plain '});
Response.End (' Hello world\n ');
}). Listen (8124);
Console.log (' Server running at http://127.0.0.1:8124/');
Front Address bar: http://localhost:8124/
Fifth Example: compiling C files
Copy Code code as follows:
#include #include int main () {printf ("Hello world!!!"); exit (0);}