搜尋

首頁  >  問答  >  主體

node.js - express的路由打印

比如下面这个是我的web服务启动项
我想打印下app.get里的req.params方法,不过好像打印不出来,
要怎么看???

var path = require('path');
var fs = require('fs');
var express = require('express');
var webpack = require('webpack');
var http = require('http');
var compression = require('compression');
var consolidate = require('consolidate');
var webpackConfig = require('./webpack.dev.conf');

//端口
var port = process.env.PORT || 8080;
var app = express();
app.engine('html', consolidate.ejs);
app.set('views', 'view');
app.set('view engine','html');

app.use(compression()); //开启 gzip

//webpack编译器
var compiler = webpack(webpackConfig);
//webpack-dev-server 中间件
var devMiddleware = require('webpack-dev-middleware')(compiler, {
    publicPath: webpackConfig.output.publicPath,
    stats: {
        colors: true,
        chunks: false
    }
});

//热更新中间件
var hotMiddleware = require('webpack-hot-middleware')(compiler);

app.use(devMiddleware);
app.use(hotMiddleware);

// 路由
app.get('/', function(req, res, next) {
    console.log(req.params)
});

//静态资源目录
app.use('/resources', express.static(__dirname + '/resources'));

app.listen(port, function(){
    console.log("node启动 监听端口:" + port);
});
PHP中文网PHP中文网2786 天前302

全部回覆(1)我來回復

  • PHP中文网

    PHP中文网2017-04-17 16:33:35

    你的路由監聽是不是以下方式?

    如果不是,可以用req.query取得請求參數。

    回覆
    0
  • 取消回覆