Since the birth of node. JS in 2009, it has grown so fast.
Strictly speaking, node. JS is a development tool for developing a variety of Web servers.
Why is node. js developing so fast and growing up, first of all, let's look at the existing problems in server-side languages, in Java, PHP, ASP. NET Server-side language, to create a new thread for each client, each thread consumes about 2MB of memory, that is, theoretically, 8GB of memory servers can simultaneously connect the maximum number of users to about 4,000. For a Web application to support more users, increase the server so that the hardware cost increases, and node. JS solves the problem by not creating a new thread for each user request, but instead triggering a processing event within node. js for each user request. That is, with node. js, you can handle client connections for up to tens of thousands of users at a time.
The high-performance V8 JavaScript scripting language is running in the node. JS server. V8 JavaScript is a high-performance JavaScript engine developed by Gooole using the C + + language, which is not limited to running in a browser, and node. JS uses it in the server, V8 a new compilation technique inside the JavaScript engine. This means that developers write high-end JavaScript script code with the C language written by the developer, which has an approximate execution efficiency in the lungs. Does that sound too big on you?
The non-blocking I/O and event loops are used in node. js, which is an improvement to achieve high performance.
You can use node. JS for application development when your application needs to handle a lot of concurrent input and output, and before you respond to the client, you don't need to do much more complex processing inside the application. For example: Chat server and e-commerce Web site or comprehensive service class Web site server.
node. JS has many built-in modules and can also introduce third-party modules.
Said so much, it is time to start, the first to install node. js, this does not say, to the official website to download and install.
For a small example, let's take a look at this tall node. JS program.
Create a new file, node. js, and write the following code:
var http = require (' http '); Introducing the HTTP Module
Http.createserver (function (req, res) {
Use the HTTP module's Createserver method to create an HTTP server application that receives client requests and responds.
Res.writehead ($, {' Content-type ': ' text/html '});
Res.write ('
Res.end (' <p>hello world</p> ');
}). Listen (3000);
Console.log ("HTTP server is listening at Port 3000.");
Yes, this is a simple node program, this small piece of code creates the server, and responds to the customer a message, in the browser input localhost:3000 can see the effect.
This article is from "Time" blog, please make sure to keep this source http://timeblog.blog.51cto.com/8650972/1582537
Step into node. js