[英]how to deal with “DEPRECATED use https://github.com/pillarjs/path-to-regexp” message
I am quite sure it is really a dummy question for more experienced programmers but I can't figure out how to fix it. 我敢肯定,对于经验丰富的程序员来说,这确实是一个虚拟的问题,但是我不知道该如何解决。 Well, the message clear says I am using some deprecated library so it is expected I upgrade it.
好吧,明确的消息说我正在使用一些不推荐使用的库,因此可以预期我将其升级。 As far as I can see, this message is related to routing functionality but I can't find how to change from "express.Router()" to some use of "require('path-to-regexp')".
据我所知,该消息与路由功能有关,但是我找不到如何从“ express.Router()”更改为“ require('path-to-regexp')”的某种用法。 Am I confused on the purpose of such message?
我对这种信息的目的感到困惑吗? If not, how to fix the program below in order to not get such "deprecated" warning?
如果不是,如何修复下面的程序,以免出现此类“已弃用”警告? As far as I understand, the code below is 100% compliance and updated with NOdeJs Express version 4.
据我了解,下面的代码是100%遵从的,并已使用NOdeJs Express版本4更新。
PS.: I am using debian and if I type nodejs --version I get: v4.2.6 PS .:我正在使用debian,如果我输入nodejs --version,我会得到:v4.2.6
server.js: server.js:
var router = express.Router();
var index = require('./routes/index').router;
app.use('/',index);
var server = app.listen(3000,function(){
});
index.js: index.js:
var express = require('express');
var router = express.Router();
router.get('/',function(req,res){
res.send("Welcome to Node JS");
});
router.get('/about',function(req,res){
res.send("This is About page");
});
var api = router.route('/api/v1/user');
api.all(function(req,res,next){
console.log(req.method,req.url);
next();
});
...
//this line is the Master
module.exports.router = router;
The problem is with your express package. 问题出在您的快递包裹上。 Updating the express module will do the trick.
更新express模块即可解决问题。
npm update express --save
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.