Node. JS HTTP Module 2

Source: Internet
Author: User

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

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.