Nodejs Tutorial (Introduction summary!) Finally found a reliable point on the internet t_t

Source: Internet
Author: User
Tags stack trace using git

I Spit Groove! I was learning slag, and then online about the Nodejs are mostly pits, simply let people to run collapse. If not recently always be asked to Nodejs, determined not to touch the ... Born on the cmd command feel incredibly tall on, although always using GIT version controller! Then I also estimate and look at this text of the small white, the same starting point, if there is a big God, kneeling to teach will kill skill, spit Groove finished!

The first is nothing but what is Nodejs?

Simply put, node. JS is the JavaScript that runs on the server.

node. JS is a platform built on the Chrome JavaScript runtime.

node. JS is an event-driven I/O server-side JavaScript environment, based on the Google V8 engine, the V8 engine executes JavaScript very quickly and with great performance.

Who is suitable to read this tutorial?

If you're a front-end programmer, you don't know a dynamic programming language like PHP, Python, or Java, and then you want to create your own service, then node. JS is a great choice.

node. JS is JavaScript running on the server, and if you're familiar with JavaScript, you'll easily learn to node. js.

Of course, if you're a back-end programmer and want to deploy some high-performance services, learning node. JS is also a great option.

Before you learn this tutorial you need to understand

Before you continue this tutorial, you should be aware of some basic computer programming terminology. If you've studied programming languages such as Javascript,php,java, it will help you get to know more about node. JS programming.

First node. JS Program: Hello world! Script mode

Here's our first node. JS Program:

Console.log ("Hello World");

Save the file with the file name Helloworld.js and execute it via the node command:

Node Helloworld.js

After the program executes, normal, the output of Hello world will be in the terminal.

That's a ghost interaction pattern.

Open terminal, type node into the command interaction mode, you can enter a code statement immediately after execution and display the results, for example:

$ node> console.log (' Hello world! ' ); HelloWorld!
Maybe that's the thing . the pros and cons of Nodejs (for interview use)

Advantages: 1. High concurrency (the most important advantage)

2. Suitable for I/O intensive applications

Disadvantages: 1. Not suitable for CPU-intensive applications; The main challenge for CPU-intensive applications is that because of the JavaScript single thread, if there are long-running computations (such as cycle), the CPU time slices will not be released, so that subsequent I/O cannot be initiated;

Solution: The decomposition of large operational tasks for a number of small tasks, so that the operation can be released in a timely manner, not blocking the initiation of I/O calls;

2. Only single-core CPUs are supported, and the CPU is not fully utilized

3. Low reliability, once the code one link crashes, the entire system crashes

Cause: Single process, single thread

Solution: (1) NNIGX reverse proxy, load balancing, open multiple processes, bind multiple ports;

(2) Open more than one process to listen to the same port, using the cluster module;

4. Open Source Component library quality is uneven, update fast, down incompatible

5. Debug is not convenient, error does not stack trace

a scene suitable for Nodejs

1. RESTful API

This is Nodejs ideal application scenario, can handle tens of thousands of connections, itself does not have too much logic, only need to request the API, organize the data to return. It essentially simply looks up some values from a database and makes them a response. Because the response is small text, inbound requests are also small amounts of text, so traffic is not high, and a machine can even handle the API needs of the busiest companies.

2. Unifying the UI layer for Web Apps

The current MVC architecture, in a sense, Web development has two UI layers, one in the browser we finally see, the other on the server side, responsible for generating and splicing pages.

Not discussing whether this architecture is good or bad, but there is another practice, service-oriented architecture, better to do the front-end dependency separation. If all of the key business logic is encapsulated as a rest call, it means that you need to think about how to build a specific application with these rest interfaces on top. Those back-end programmers don't worry about how specific data is delivered from one page to another, and they don't have to worry about whether user data updates are asynchronously acquired through Ajax or by refreshing the page.

3. Application of a large number of Ajax requests

For example, the personalization application, each user sees the page is different, the cache is invalid, needs to initiate the AJAX request when the page loads, the NODEJS can respond the massive concurrent request. In summary, Nodejs is suitable for scenarios where high concurrency, I/o intensive, and small business logic are used.

Nodejs Tutorial (Introduction summary!) Finally found a reliable point on the internet t_t

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.