recherche

Maison  >  Questions et réponses  >  le corps du texte

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中文网2785 Il y a quelques jours298

répondre à tous(1)je répondrai

  • PHP中文网

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

    你的路由监听是不是以下方式?

    如果不是,可以用req.query获取请求参数。

    répondre
    0
  • Annulerrépondre