Recent intensive study of the next Nodejs (Before learning PHP, calculate the beginning of it, but the time relationship, haven't written articles, follow up to do Android and Big data, in short, busy ha, plan PHP to line up to the back, also please the majority of small partners do not worry)
First copy:node. JS is a server-side JavaScript runtime with nonblocking (non-blocking) and event-driven (Event-driven) and so on, node. JS uses V8 engine, similarly, node. JS implements a similar Apache and the Nginx Web service that allows you to build JavaScript-based web apps.
It sounds so big, so you have to give some examples to keep the audience eye-candy.
List A php example first
$result = mysql_query (' select * from TestTable ');
Print_r ($result);
It seems that after the above code, we have doubts, I/O operations and before the data back, the process has been blocked state, perhaps people think this is nothing. But have you ever thought
If the delay is 10ms to a few minutes, it will occur:
1, the hard disk is performing maintenance operations, read/write are paused
2, load increase, database query slow
Do people think of asynchronous programs at this time?
The simplest is Ajax in jquery.
$.post ('/test.json ', function (data) {
Console.log (data);
}}
And node is almost like this.
var fs = require (' FS ');
Fs.readfile ('./resource.json ', function (err,data) {
Console.log (data);
})
As for how to install node, it's not much to say.
Node can do too much, people are more concerned about the Web development, is also the current comparison of fire.
First, a little dry, create a file app.js, the content is as follows, and then install the dependency----NPM install HTTP;
var http=require (' http ');
Http.createserver (function (req,res) {
Res.writehead (200,{' content-type ': ' Text/plain ');
Res.end (' Hello world\n ');
}). Listen (3000);
Console.log (' Server runing at Http://localhost:3000/');
Browser input http://localhost:3000
You'll see HelloWorld.
So I got started ...
(a series of articles will continue to be published as a result of the time relationship.)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Nodejs Beginner-----HelloWorld