Detailed introduction to nodejs (combining multiple articles)

Source: Internet
Author: User

Node. JS is a set of JavaScript toolkit used to write high-performance network servers. A series of changes started from this. Specifically, node. js assumes that you are running Linux or Mac OS X in the POSIX environment. If you are running Windows, install mingw to obtain a POSIX-like environment. In node, HTTP is the first priority. Node is optimized to create an HTTP server, so most examples and libraries you can see on the Internet are concentrated on the Web (HTTP framework, template library, etc ).

First, download the installation from the http://nodejs.org. My version is 0.6.6. The installation is very simple. The next step is the next step.
My installation directory is c: \ Program Files (x86) \ nodejs.

1. helloworld
Create a new file "Hello. js" in the nodejs installation directory and click "One Line ".Code Copy codeThe Code is as follows: console. Log ('hello, nodejs .');

Go to the command line console, go to the nodejs directory, and tap node hello. js.

The console outputs "Hello, nodejs ."
Ii. Web helloworld
Create an HTTP. js file in the nodejs installation directory. The Code is as follows:

Copy code The Code is as follows: var HTTP = require ("HTTP ");
HTTP. createserver (function (request, response ){
Response. writehead (200, {"Content-Type": "text/html "});
Response. Write ("Hello world! ");
Response. End ();
}). Listen (8000 );

Start the service in the command line and tap node HTTP. js

Open the address bar of the browser and enter http: // localhost: 8000/. The Hello world is displayed! It is successful.

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.