Getting started with Node. js

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 Linux or Mac OS X is running in the POSIX environment. In Windows, MinGW must be installed 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 on the Internet are concentrated on the web (http framework, template library, etc ). Node. js is not a JS application, but a JS running platform that displays Node. the js name may be mistaken for beginners as a Javascript application. In fact, Node. javascript is written in C ++ and is a Javascript runtime environment. Why is C ++ used? According to Node. ryan Dahl, founder of js, recalled that he initially wanted to use Ruby to write Node. but later he found that the performance of the Ruby virtual machine could not meet his requirements. Later he tried to use the V8 engine, so he chose the C ++ language. Node. js uses event-driven and asynchronous programming to design Node for network services. js is designed with event-driven as the core. The vast majority of Apis it provides are event-based and asynchronous. An important advantage is that the system resources are fully utilized, and the execution of code does not need to be blocked to wait for a certain operation to complete. limited resources can be used for other tasks. The features of Node. js are also bold in design. It runs in single process and single thread mode (surprised, right? This is consistent with the Javascript running mode). The event-driven mechanism is Node. js is implemented through highly efficient maintenance of the event loop queue by a single internal thread. It does not have multi-threaded resource occupation and context switching, which means that in the face of large-scale http requests, Node. with event-driven processing, js gets used to network service developers in traditional languages and may be very familiar with multi-thread concurrency and collaboration, but is familiar with Node. js, we need to accept and understand its features. Another feature of Node. js is that it supports Javascript as a programming language. Javascript, as the main language of front-end engineers, has a considerable appeal in the technical community. The anonymous functions and closure features of Javascript are very suitable for event-driven and asynchronous programming. Javascript has good performance in dynamic languages, in addition, the V8 engine is also the best of its kind, so Node. js performance also benefits. Hello World is our first Node. js application: "Hello World ". Open your editor and create a hello. js file. Write code to save the file and run it through Node. js. Console output 1 console. log ('hello, nodejs. '); Web output 1 var http = require ("http"); 2 http. createServer (function (request, response) {3 response. writeHead (200, {"Content-Type": "text/html"}); 4 response. write ("Hello World! "); 5 response. end (); 6}). listen (8000); open the browser address bar and enter http: // localhost: 8000/. The output result is displayed on the webpage.

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.