Good programmers know the web front end of the learning process learning route nodeJs nodejs

  Good programmers know the web front end of the learning process learning route nodeJs nodejs, nodeJs only heard, not seen, never played. From the novice to start, I want to slowly master it.

  First of all, I want to know what nodeJs that? I used to do.
  And network node from the official website:

Node.js is a JavaScript runtime environment Chrome V8 engine. 
Node.js uses an event-driven, non-blocking I / O model, making it lightweight and efficient.

Node.js is a high-performance network servers for writing JavaScript toolkit, a series of changes began. More unique is that, Node.js will assume POSIX environment running under Linux or Mac OS X.
If you are in Windows, then you need to install MinGW to obtain a copy of the POSIX environment. In the Node, Http is paramount. Node optimized for creating http server, so most of the examples and libraries see on the Internet are focused on the web (http frameworks, templates, libraries, etc.).

  Do what

  1. A web server;

  2. javascript toolkit;

  3. And http are closely related.
  4. Quickly build web services and applications;

  5. Google v8 engine package.

What is it nodeJs in the end, it is a server-side js operating platform, is a javascript runtime environment and libraries. You can write server-side back-end system or Javascript code, Node.js to be interpreted. Html php will encounter as interpreted by the php, jsp jvm interpreted by the same.

  He also has many features not one by one example. Nodejs as a rising star in the background, there are many attractive places: single-threaded, V8 virtual machine, event-driven, non-blocking IO; under nodejs can not add additional thread, the task can still be processed and a single --node thread. It is to carry out the operation by an event polling, which we can take full advantage of this, as much as possible to avoid blocking, instead.

  That nodejs is doing what? Server similar to Java, web applications;

  for example:

var http = require('http');

server = http.createServer(function (req, res) {

   res.writeHeader(200, {"Content-Type": "text/plain"});

   res.end("Hello");

})

server.listen(8000);

console.log("httpd start @8000");

  Nodejs environment to ensure a successful installation, which is performed by the compiler in the browser address bar enter localhost: 8000, you can see the output.

nodeJS advantages and disadvantages

  Advantages: 1. high concurrency

  1. For I / O-intensive applications

  Disadvantages: CPU 1 is not suitable for intensive applications; JavaScript due to the thread, if there is calculated (such as a cycle) in the long run, causes the CPU time slice will not be released, so that subsequent I / O can not start;

  Solution: break up large computing tasks into multiple small tasks so that operations can be timely release and is not blocking I / O calls initiated;

  1. Only supports single-core CPU, can not make full use of CPU

  2. Low reliability, once a part of the code crashes, the whole system crashes

  The reason: single-process, single-threaded

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

  (2) open multiple processes with a monitor port, the use of cluster module;

  1. Open source component libraries of varying quality, updated quickly, not downward compatible

  2. Debug inconvenient, no error stack trace

Guess you like

Origin blog.51cto.com/14479068/2425663