Reached out to the legendary Server-sidemo-crpt. Backend JS is undoubtedly the node of RyanDahl. js, and jaxer developed by the aptanaIDE provider. Here we will discuss node. to use js, first download node. js, decompress it to the E disk, change it to node, start the menu, Enter cmd, and use the cd command to switch to the decompressed directory of nodejs:
Example 1: hello world.
Create a hello. js file in the node directory, and then enter:
The Code is as follows:
Var sys = require ("sys ");
Sys. puts ("Hello world ");
Then, enter the node hello. js command in the nameboard to view the output result Hello world.
Example 2: hello world2.
Okay. This time we try to output hello world from the browser. Create http. js in the node directory and enter:
The Code is as follows:
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, enter the command node http. js in the naming stage, and enter http: // localhost: 8080/in the browser/
Example 3: hello world2.
Node. js provides a Buffer class for converting strings of different encodings. Currently, three types are supported: 'ascii ', 'utf8', and 'binary '. For details, see here.
The Code is 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 ));
Example 4: hello world3.
The Code is as follows:
// Synopsis. js
// Synopsis abstract, synopsis, outline
Var http = require ('http ');
Http. createServer (function (request, response ){
Response. writeHead (200, {'content-type': 'text/plain '});
Response. end ('Hello World \ n ');
}). Listen (8124 );
Console. log ('server running at http: // 127.0.0.1: 8124 /');
Front-end address bar: http: // localhost: 8124/
Example 5: compile a C file
The Code is as follows:
# Include int main () {printf ("Hello World !!! "); Exit (0 );}