我是新来的node.js,这个错误让我付出了很多努力,所以我分享这个。
我只尝试在我的 index.js 中声明express和一些基本路由器:
const express = require('express');
const app = express();
app.get('/api/courses', (req, res)=>{
res.send(courses);
});
app.get('/api/courses:id', (req, res)=>{
const course = courses.find(c => c.id === parseInt(req.params.id));
if (!course) res.send('The given id was not found...');
res.send(course);
});
app.get();
Run Code Online (Sandbox Code Playgroud)
错误详细信息:
\node_modules\path-to-regexp\index.js:63 path = ('^' + path + (strict ? '' : path[path.length - 1] === '/' ? '?' : '/ ?')) ^
类型错误:无法在新层 (C:\Users...\node_modules) 的 pathtoRegexp (C:\Users...\node_modules\path-to-regexp\index.js:63:49) 处读取未定义的属性“长度” \express\lib\router\layer.js:45:17) 在 Function.route (C:\Users...\node_modules\express\lib\router\index.js:494:15) 在 Function.app.(匿名函数)[as get] (C:\Users...\node_modules\express\lib\application.js:481:30) at Object. (C:...\index.js:24:5) 在 Module._compile (module.js:652:30) 在 Object.Module._extensions..js (module.js:663:10) 在 Module.load (module.js:565:32) 在 tryModuleLoad (module.js:505:12) 在 Function.Module._load (module.js:497:3)
| 归档时间: |
|
| 查看次数: |
8819 次 |
| 最近记录: |