1. Node. JS is the Javascrip that runs on the server.
2. Node. JS is a platform based on a chrome Javascrip run-time resume.
3. Node. JS is a non-blocking I/O server-side JavaScript environment, based on Google's V8 engine, the V8 engine executes JavaScript very quickly.
See the introduction of Xia Guan Network:
node. JS is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. node. JS uses an event-driven, non-blocking I/O modelthat makes it lightweight and efficient, perfect for data-intensive re Al-time applications that run across distributed devices.
node. JS Usage Scenarios
See the pros and cons of node JS before you look at his usage scenarios.
First, Node JS features
1. He is a JavaScript runtime environment
2, rely on the chrome V8 engine for code parsing
3. Event-driven non-blocking I/O
4, lightweight, scalable, suitable for real-time data interactive applications
5, single process, single thread
What is event-driven? What non-blocking I/O can refer to my article, which describes the asynchronous IO model in detail, can be used to understand the benefits of Node JS's event-driven and non-blocking I/O.
Http://www.cnblogs.com/luotianshuai/p/5098408.html
Second, Node JS Excellent, shortcomings
Advantages:
1, concurrency High is the choice node JS important advantages
2. Suitable for I/O intensive applications
Disadvantages :
1, not suitable for CPU-intensive applications, CPU-intensive applications to node challenges mainly: Because of JavaScript single-threaded reason, if there are long-running computations (such as cycle), will cause the CPU time slices can not be released, so that subsequent I/O can not 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, does not block the initiation of I/O calls.
2, because it is single process single-threaded only use one CPU, can not fully use the CPU to cause the waste of resources
3, low reliability, a piece of code crash, the whole system will crash
Reason: He is single-threaded, but single-process
Workaround:
3.1, Nginx reverse proxy load balancing open multiple processes, bind multiple ports
3.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, downward incompatible
5, Debug inconvenient, error does not stack trace
Third, suitable for node JS scene
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. Unify the UI layer of the Web application
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, a large number of Ajax requests
For example, the personalization application, each user sees the page is different, the cache is invalid, needs to launch the AJAX request when the page loads, or the barrage system many users simultaneously through the comment, 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.
Note: Node js is very good it can implement a lot of applications, when we want to use it to complete an application, the need to consider is appropriate to do it.
Node JS Installation Configuration
1, download the source code more version: https://nodejs.org/en/download/
Cd/work/app/wget http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz
2. Extracting source code
TAR-ZXVF node-v0.10.24.tar.gz
3. Compile and install
CD node-v0.10.24./configure--prefix=/work/appmakemake Install
4, configure Node_home, enter the profile edit environment variable
Vim/etc/profile
Set the NODEJS environment variable to add the following on the export PATH USER LOGNAME MAIL HOSTNAME histsize histcontrol line
Export Node_home=/work/app/node/0.10.24export path= $NODE _home/bin: $PATH
: Wq Save and exit, compile/etc/profile make configuration effective
Source/etc/profile
Verify that the installation configuration is successful
Node-v
Output v0.10.24 indicates a successful configuration
NPM Module Installation Path
/work/app/node/0.10.24/lib/node_modules
MAC Install node JS
Node JS is installed on the server to quickly develop node JS so install node JS on Mac and use Pycharm to develop
First, install node JS
https://nodejs.org/en/download/
Download and install node JS it will install node. js and NPM (Node Package Manager) on your machine.
Second, install the Pycharm plug-in
Both plugins are installed under the
Then you can create the node JS project.
The first application of Node JS
If we use PHP to write back-end code, we need an Apache or Nginx http server, with MOD_PHP5 modules and php-cgi.
From this perspective, the entire "Receive HTTP request and provide WEB page" requirement does not need PHP to handle at all.
But for node. JS, the concept is completely different. When using node. js, we are not only implementing an application, but also implementing an entire HTTP server. In fact, our web application and the corresponding Web server are basically the same. Kinda like my big Django and tornado
Before we create the first "Hello, world!" app for node. JS, let's start by understanding which parts of the node. JS application are composed:
Required Module : We can use the Require directive to load the node. JS module.
Create server : The server can listen to the client's request, similar to Apache, Nginx and other HTTP server.
receive requests and response requests : The server is easy to create, the client can send HTTP requests using a browser or terminal, and the server receives the request and returns the response data.
1. Introduction of Node JS module
Use the require directive to load the HTTP module and assign the instantiated HTTP value to the variable http:
var http = require (' http ');
2. Create a service
#!/usr/bin/env node//require instructions to load the node. JS module and create the object through it var http = require (' http ');// Through the Createserver method and using the Listen method to bind port 8888, the Request,response parameter is used to receive and the corresponding data http.createserver (function (request,response) { //Send HTTP Department //http status value: $ OK //content Type Text/plain response.writehead ($, {' Content-type ': ' Text/plain '}); Send the corresponding data "Hello World" response.end (' Hello world\n ')}). Listen (8888);//terminal print content//console.log haha ~ used to server here Terminal output ~ So, node JS is the JavaScriptconsole.log (' Server running at http://127.0.0.1:8888 ') running on the server side.
3. Execute code
The above code we have completed a working HTTP server.
Use the node command to execute the above code:
Luotimdemacbook-pro-2:bin luotim$ node Www.js Server running at http://127.0.0.1:8888
Test:
node. js