node. JS Express II

Source: Internet
Author: User

Long time no write, read blog today, feel the need to continue to write node. js, Finish. Originally thought of the small Cui class continue to talk about, for other reasons also delayed, see later there is no chance it. No nonsense, 123 start.

I. Exoress Request Object

For the request object has done network this piece of should be not unfamiliar, iOS, C # will have, other languages basic will have, node. JS is no exception, after all, is the HTTP protocol.

varExpress = require ('Express');varApp =Express (); App.listen (8080); app.Get('/user/:userid', Function (req, res) {//the original URL string of the requestConsole.log ("url:\t"+Req.originalurl); //the string of the protocol, such as HTTP, httpsConsole.log ("Protocol:"+Req.protocol); //the requested IP addressConsole.log ("ip:\t"+Req.ip); //The path portion of the requested URLConsole.log ("path:\t"+Req.path); //host name of the requestConsole.log ("host:\t"+req.host); //How to request get, post, etc.Console.log ("method:\t"+Req.method); //the query string portion of the requestConsole.log ("query:\t"+json.stringify (req.query)); //A Boolean value that is true when the last modification matches the current matchConsole.log ("fresh:\t"+Req.fresh); //A Boolean value that is false when the last modification matches the current matchConsole.log ("stale:\t"+Req.stale); //Boolean value, True when establishing a TLS linkConsole.log ("secure:\t"+req.secure); //a method, if the character set specified by CharSet is supported by TrueConsole.log ("utf8:\t"+ Req.acceptscharset ('UTF8')); //method to return the value of the headerConsole.log ("Connection:"+ req.Get('Connection')); //the object form of the request headerConsole.log ("Headers:"+ json.stringify (req.headers,NULL,2)); Res.send ("User Request");});

node. JS Express II

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.