Chapter One (http://www.cnblogs.com/yiyistar/p/7448150.html) simple set up a server of our own, the second chapter to gradually, I do not like the space is too long, so each space content less, Separate chapters.
Now that I've set up the environment, how do I look at HTML pages? very simple!! Filea system with Nodejs filesystem
The Nodejs fs provides the operation of the file via the built-in module. What we're going to talk about here is the fs.readfile API. The main purpose of this method is to obtain the contents of the file
Let Fs=require (' FS ')
function (err, data) { if (err) { /// Deal with error. Else { // Deal with data. }});
As described in the first chapter, when require () this built-in module, call the ReadFile () method, this method accepts two parameters, the first is the path of the file, the second parameter is a back-off function.
This callback function takes two arguments, the first err, which indicates the request for the contents of the file, an error occurred, and the second parameter represents the data returned after the file read was successful.
Doesn't anyone have a question? What the hell is that pathname thing? Here, to be again Amway a Nodejs module, is the URL module, we put it in the same way, directly require () go in it can
Node. JS HTTP Module 2