Nodejs Beginner-----HelloWorld

Source: Internet
Author: User
Tags php example install node

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

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.