简体   繁体   English

如何处理“已弃用,请使用https://github.com/pillarjs/path-to-regexp”消息

[英]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.

相关问题 如何将路径与正则表达式与路径到正则表达式匹配? - How to match path with regexp with path-to-regexp? 如何在浏览器中使用“https://github.com/ovvn/dom-to-pdf” - How can I use `https://github.com/ovvn/dom-to-pdf` in a Browser 如何使用路径到正则表达式来匹配所有不以 /api/ 开头的路径? - how to use path-to-regexp to match all paths that's not starting with /api/? 如何将vue-router中的可选段与路径到正则表达式匹配 - How to match an optional segment in vue-router with path-to-regexp 寻找与正则表达式路径完全相反的方法 - Looking for the exact opposite of path-to-regexp 无法找到模块“路径到正则表达式” - Unable to find module 'path-to-regexp' 如何为Tween.js分配额外的属性(https://github.com/sole/tween.js/) - How to assign extra attributes to Tween.js ( https://github.com/sole/tween.js/ ) 来自https://github.com/RubaXa/Sortable的功能要求 - Function required from https://github.com/RubaXa/Sortable 路径到正则表达式抛出类型错误:无法读取未定义的属性“长度” - Path-to-regexp throws TypeError: Cannot read property 'length' of undefined 如何使用github.com/1000hz/bootstrap-validator的自定义验证器 - How to use custom validators of github.com/1000hz/bootstrap-validator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM