Dom framework cannot be released as scheduled because it runs to another city and has no computers. In this period, the most urgent need was to seek a super lightweight backend to build up my framework, so I reached out to the legendary server-side javascrpt. Backend JS is undoubtedly the node. js of Ryan Dahl, and jaxer developed by the Aptana ide provider.
Http://github.com/tlrobinson/narwhal
First download node. JS, decompress it to the E disk, change it to node, then Enter cmd in the menu, 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:
// Var sys = require ("sys"); var sys = require ("util") SYS. Puts ("Hello World ");
Then, enter the command in the nameboard.Node hello. jsThe output result of the nameboard Hello world is displayed.
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:
// Var sys = require ("sys"); var sys = require ("util") var HTTP = require ("HTTP"); http. createserver (function (request, response) {// response. sendheader (200, {"Content-Type": "text/html"}); response. writeheader (200, {"Content-Type": "text/html"}); response. write ("Hello world! "); // Response. close (); response. end ();}). listen (1, 8080); sys. puts ("server running at http: // localhost: 8080 /");
Then, enter the command in the nameboard.Node HTTP. jsIn the browser, enterHttp: // localhost: 8080/
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.
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.
// 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
# Include
# Include
Int main (){
Printf ("Hello world !!! ");
Exit (0 );
}