node leaves the "HTTP Server" layer out and targets the browser user directly
If PHP is to be configured with a powerful and complex HTTP server, such as Apache, IIS or Nginx, you also need to configure PHP as a module of the HTTP server, or invoke the PHP interpreter using the FASTCGI protocol. This architecture is the way the browser-http server-php interpreter is organized
Node's biggest feature is asynchronous I/O, which is known as a single thread, and is not blocked, as is the case with PHP multithreading, for example, when a thread encounters an I/O operation, does not wait for I/O operations to complete or data to return, but simply sends I/O requests to the operating system. And in the continuation of the next sentence. Conversely, multithreading is blocking, blocking what to do? Open one more thread to do the bad? (Please self-Baidu) the following two pictures more clearly understand
Multithreading:
Single Thread
Here's what we're going to learn tonight.
varHTTP = require ("http");//Creating an HTTP modulehttp.createserver (function (req,res) {Res.writehead ( $,{'Content-type':'text/html'}); Res.write (""); Res.end ("<p>node</P>");}). Listen ( the);//Creating PortsConsole.log ("Run successfully")
Getting started writing rotten statements is creating node's core module HTTP
Creating a template node provides exports and require two objects.
Exports is a public excuse for modules require is to get the interface usage of the module is very simple
// module.js Name;exports.tagname = function (a) { Name = A;} exports.tagtable = function () {Console.log ( " i am +name)}
// GetModule var Get = require ("./module"); get. tagname ("LEE"get. tagtable ();
As shown in the output is Lee
But this is all one-way loaded, for example
var get = require ( " ./module " ); get . tagname ( " lee " var get = require ( " ./module " get . tagname ( " lee2 " get . tagtable ();
The output is LEE2 because it's all pointing to the same one, and the second one overrides the first one, so it's LEE2.
Sometimes writing the code is a little bit like this.
function Hello () { var name; this. SetName = function (thyname) { = thyname; }; this. SayHello = function () { console.log (' + Name );
var Hello = require ('./hello'new hello (); Hello.setname (' Lee'
The output of "Lee";
Summing up what I learned tonight, I have a clearer understanding of the module
Continue to grow in ....
Nodejs Introductory note (i)