首页 > 代码库 > 参数传递

参数传递

var express = require (‘express‘);
var bodyParser = require(‘body-parser‘);
var url =require(‘url‘);
var qs=require(‘querystring‘);
var app = express;

app.listen(‘3000‘,function () {
console.log(‘app is running‘)

});

//get
app.get(‘/‘,function (req, res, next) {
var params = req.query;
console.log(params);
res.send(paeams);

});


//router
app.get(‘/:id‘,function (req, res, next) {
var params = req.params;
console.log(params);
res.send(params);

});


//post
app.post(‘/post‘,function (req, res, next) {
var params = req.body;
console.log(params);
res.send(params);
});



//url

app.get(‘/url‘,function (req, res, next) {
var urlString = "http://cnodejs.org/?tab-all&page=1";
//URL解析 问号后面的内容
var queryUrl = url.params(urlString).query;
console.log(queryUrl);


//params to boject
var obj = qs.parse(queryUrl);
console.log(obj);

res.send(obj.tab+"---"+obj.page);
});

参数传递