First Glimpse of Nodejs

Source: Internet
Author: User

What exactly is node. js?
    1. Node. JS is a server-side JavaScript interpreter;
    2. is a platform built on the chrome JavaScript runtime environment, which is important, andnode. JS is not a language, but a platform;
    3. Committed to making the construction of fast, stable network procedures more simple;
    4. Features event-driven and non-blocking I/O, making it lightweight and efficient;
    5. Ideal for running data-intensive real-time applications on distributed devices.

If you want to know about node. js, then use it to say hello to the world!

1. Create a JS file in the Nodejs file plus the following, for example: Hello.js

The contents of the 2.hello.js file are as follows:

varHttp=require ('http');//introducing the HTTP moduleHttp.createserver (function (request,response) {//Create a Web server//callback function so that creating the server method does not block theResponse.writehead ( $,{'ContentType':'Text/plain'}); Response.End ('Hello world!\n');}). Listen (8124); Console.log ('Server running at http://127.0.0.1:8124/');

3. Bring up Cmd.exe, use CD \.....\nodejs to reach Nodejs file directory, and then enter node Hello.js to run

4. Open the browser, enter the port number you set in the Address bar http://127.0.0.1:8124/, refresh, display "Hello world!"

Ii. Advantages of node. JSNodejs, as an emerging background language, has a lot of attractions: RESTful API single-threaded node. JS can still process tasks in parallel without adding additional external threads--node.js is single-threaded.  It implements parallel operations through event polling, which we should take advantage of--avoid blocking operations as much as possible and use non-blocking operations instead. Non-blocking IO V8 virtual machine Event driver Iii. What is Node designed to solve?

Node's avowed goal is "to provide a simple way to build scalable network programs." What is wrong with the current server program? Let's do a math problem. In languages such as Java™ and PHP, each connection will generate a new thread, and each new thread may require 2 MB of companion memory. On a system with 8 GB of RAM, theoretically the maximum number of concurrent connections is 4,000 users. As your customer base grows, you must add more servers if you want your WEB application to support more users. This, of course, increases costs such as server costs, traffic costs, and labor costs. In addition to these cost increases, there is a potential technical problem that users may use different servers for each request, so any shared resources must be shared across all servers. For all these reasons, the bottleneck in the overall WEB application architecture, including traffic, processor speed, and memory speed, is the maximum number of concurrent connections that the server can handle.

Node solves this problem by changing the way it connects to the server. Each connection emits an event that runs in the Node engine's process instead of generating a new OS thread for each connection (and allocating some companion memory for it). Node claims that it will never deadlock, because it does not allow locks at all, and it does not directly block I/O calls. Node also claims that the server running it can support tens of thousands of concurrent connections.

Now that you have a program that can handle tens of thousands of concurrent connections, what can you actually build through Node? If you have a WEB application that needs to handle so many connections, it would be a "scary" thing! It's a question of "If you have this problem, then it's not a problem at all." Before answering the above questions, let's look at how Node works and how it's designed to work.

Iv. Application direction of node. JS in a few years, node. JS has evolved into a mature development platform that has attracted many developers.  There are many large, high-traffic sites that are developed using node. JS, and developers can use it to develop some fast-moving web frameworks. In addition to Web applications, Nodejs is also used in many ways, and this article takes a count of the ten amazing projects that Nodejs has developed in other areas, such as application monitoring, media streaming, remote control, desktop and mobile applications, and more.

First Glimpse Nodejs

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.