First download node.js, then unzip it to the E drive, rename it to node, then enter cmd in the start menu, and use the cd command to switch to the nodejs decompression directory:
First example: hello world. Create the hello.js file in the node directory, and then enter:
var sys = require("sys");
sys.puts("Hello world");
Then we enter it in the naming table Command node hello.js, and you can see the naming console output Hello world.
Second example: hello world2. Okay, this time we try to output hello world from the browser. Create http.js in the node directory, and then enter:
var sys = require("sys"),
http = require("http");
http.createServer(function(request, response) {
response.sendHeader(200, {"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 naming platform and http://localhost:8080/ in the browser
The third example: hello world2.
node.js provides a Buffer class for converting strings of different encodings. Currently three types are supported: 'ascii', 'utf8' and 'binary'. See
here
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.
//synopsis.js
/ /synopsis summary, synopsis, outline
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content- Type': 'text/plain'});
response.end('Hello Worldn');
}).listen(8124);
console.log('Server running at http ://127.0.0.1:8124/');
Front-end address bar: http://localhost:8124/
Fifth example: Compiling C files
#include #include int main(){ printf("Hello World!!!"); exit(0); }