NodeJS取参的四种方法req.hostname/req.params/req.path/req.query

启动服务器

node app.js

输入网址

http://127.0.0.1:9091/idx/:9?name=tom&addr=usa

app.js

'use strict';

let express = require('express') ;
let app = express() ;


app.get('/idx/:pageNum',function( req , res ){

  console.log( req.hostname );  // '127.0.0.1'
  console.log( req.params );    // { pageNum: ':9' }
  console.log( req.path );      // /idx/:9
  console.log( req.query );     // { name: 'tom', age: '18' }

  res.send( '

test

'
) ; }) ; app.listen(9091,'127.0.0.1',function(){ console.log('server is running at port 9091') ; });

你可能感兴趣的:(5,Node.Js)