The method of common attributes express module req, res parameters
Express the require = const ( 'Express'); const = express.Router Router () router.get ( '/', (REQ, RES) => { // the Request // req.baseUrl based routing address // req.body post data sent parsed object // cookies sent by the client data req.cookies // req.hostname host address to remove the port number // req.ip view the client's ip address // req.ips proxy IP address // a pair of backup req.url req.originalUrl // req.params use /: id /: name matching the params // req.path path part of the request URL contains req.protocol http or https protocol // // req.query parsed query string object password = & zhangsan = username 123 {username: zhangsan} // req.route current route matches a regular expression // req.params acquisition parameters matching route // req.get acquisition parameters in the request header // req.is judgment request what type of file) Set Cookie // res.cookie ( 'zhangsan1', 'lisi2', { // req.param (key name) used to obtain the parameters of a particular route matches // the Response // res.headersSent see if the response http response http header // res.append (name, value) additional http response header // res.attachment (file path) in response to a file request // res.cookie () set Cookie //res.setHeader('Content-Type','text/html;charset=utf8 ') // res.append (' Content- type ',' text / HTML; charset = UTF8 ') // res.append (' Hehe ',' 1008 ') // res.append (' haha ',' 1008 ') // res.attachment (' ./ xx.zip ') // Content-Disposition: Attachment; filename = "xx.zip" // res.clearCookie (cookieName) delete the cookie // res.cookie (' zhangsan ',' lisi ') set the cookie // httpOnly:true, // path: '/admin', The maxAge //: 900000, // 'default':function() { Secure //: to true, // Signed: to true //}) // res.clearCookie ( 'zhangsan') // res.download (file path path) with the attachment process parameters similar to the downloaded file is a file address / / res.end http with the module // res.format () type file format negotiation request matches the file type negotiation // res.format ({ // 'text / Plain': function () { // res.send ( 'Hey'); //}, // 'text / HTML': function () { // res.send ( '<P> Hey </ P>'); //}, // 'file application / JSON ': function () { // res.send ({Message:' Hey '}); //}, // // The Request log 406 and the respond with // res.status (406) .send ( 'Not Acceptable The'); //} //}); // res.get ( 'Key') fetch response data header // res.json () returns json data is automatically set in response to json header Content-type format file application / json // res.json ({ // XX: 100 //}) // res.json ({ // XX : 100 //}) // JSONP is to use the browser to load the server's file does not exist other cross-domain problems // ajax request will have cross-domain problem // res.setHeader ( 'Content-Type' , 'text / JavaScript; charsert = UTF8 ') // res.end (typeof $ `{req.query.callback} ==' function '$ {req.query.callback} ({AA: 100}?): null`) // res.jsonp ({aaa:100}) // address of the access redirection to another jump address Res.redirect // (301, '/ API / AES') // Jade Express // res.render ( 'index', {title: "Hehe", Test: "23 is"}) // res.send ( ' ') may be any type of data transmission of data // res.sendFile () to send the file status code // res.sendStatus (200) disposed transmits // res.set (' Content-type ' ,' text / plain ') // set the response header // res.status (200 is) // set status code // res.type (' ') // file type response directly // res.type (' PDF ') // RES .send ({AA: 100}) // res.end ( 'OK') // res.end ({AA: 100}) // res.end ( 'Hello') // res.end (REQ. GET ( 'the Accept-Language')) // res.json ({ // IS: req.is ( 'text / HTML') // }) // res.json({json ({ // type: req.baseUrl, // hostname:req.hostname, // // ip:req.ip, // // ips:req.ips, // // route:req.route, // ct:req.get('Accept'), // cs:'22' // }) }) router.get('/:id/:date',(req,res)=>{ console.log(req.params) // res.json(req.params) res.end(req.param('date')) }) router.get('/aes',(req,res)=>{ res.json({ type:req.baseUrl }) }) module.exports = router