Server-side JavaScript scripting Node.js using Getting Started _javascript tips

Source: Internet
Author: User
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);}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.