Node.js 错误:在nodejs/expressjs中的app.use.res.render.message处找不到

Node.js 错误:在nodejs/expressjs中的app.use.res.render.message处找不到,node.js,express,Node.js,Express,我已经设置了新的express(nodejs)项目,当我尝试运行url时,它显示了404未找到错误。但我没有修改任何一行代码和目录结构。我已经使用expressgenerator命令创建了expressproject的结构 有人能为我提供以下问题的建议吗? -为什么默认代码不运行? -我应该如何设置我的项目目录以防止写入此长url。 -如何将我的聊天应用程序与yii1项目集成 以下是我的代码详细信息 网址: 目录结构: wchat/wnode/users wchat:php项目 wnode:实现

我已经设置了新的express(nodejs)项目,当我尝试运行url时,它显示了404未找到错误。但我没有修改任何一行代码和目录结构。我已经使用expressgenerator命令创建了expressproject的结构

有人能为我提供以下问题的建议吗? -为什么默认代码不运行? -我应该如何设置我的项目目录以防止写入此长url。 -如何将我的聊天应用程序与yii1项目集成

以下是我的代码详细信息

网址:

目录结构: wchat/wnode/users wchat:php项目 wnode:实现即时通知和聊天的节点目录 用户:模块

代码文件: app.js

index.js

   var express = require('express');
   var router = express.Router();

   /* GET home page. */
   router.get('/', function(req, res, next) {
   res.render('index', { title: 'Express' });
   });

   module.exports = router;
users.js

var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});

module.exports = router;
错误:

Not Found
404
Error: Not Found
    at app.use.res.render.message (/var/www/html/wchat/wnode/app.js:30:13)
    at Layer.handle [as handle_request] (/var/www/html/wchat/wnode/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/var/www/html/wchat/wnode/node_modules/express/lib/router/index.js:312:13)
    at /var/www/html/wchat/wnode/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/var/www/html/wchat/wnode/node_modules/express/lib/router/index.js:330:12)
    at next (/var/www/html/wchat/wnode/node_modules/express/lib/router/index.js:271:10)
    at /var/www/html/wchat/wnode/node_modules/express/lib/router/index.js:618:15
    at next (/var/www/html/wchat/wnode/node_modules/express/lib/router/index.js:256:14)
    at Function.handle (/var/www/html/wchat/wnode/node_modules/express/lib/router/index.js:176:3)
    at router (/var/www/html/wchat/wnode/node_modules/express/lib/router/index.js:46:12)

看看你的路线

app.use('/', routes); -> handlers GET on localhost:3000
app.use('/users', users); -> handles GET on localhost:3000/users
因此没有什么需要处理的
localhost:3000/wchat/wnode/users
。因此,404

如果要处理类似于
localhost:3000/wchat/wnode/users
的内容, 你需要有一条像这样的路线

router.verb('/wchat/wnode/users', function (req, res, next) {
  // handle whatever you want.
});

看看你的代码和你想得到的url,我建议你熟悉一下express是如何处理路由的。更多信息查看您的路线

app.use('/', routes); -> handlers GET on localhost:3000
app.use('/users', users); -> handles GET on localhost:3000/users
因此没有什么需要处理的
localhost:3000/wchat/wnode/users
。因此,404

如果要处理类似于
localhost:3000/wchat/wnode/users
的内容, 你需要有一条像这样的路线

router.verb('/wchat/wnode/users', function (req, res, next) {
  // handle whatever you want.
});

看看你的代码和你想得到的url,我建议你熟悉一下express是如何处理路由的。更多信息

Its
res.render('index',{title:'Express'})
not
es.render('index',{title:'Express'})。我没有看到您试图如何处理路由中的url
wchat/wnode/users
。使用route handler
users.js更新您的问题
谢谢swaraj,因为复制粘贴可能会被删除。routes/users
在哪里?我已经更新了users.js。即使没有用户,默认路由索引也无法工作,并显示相同的错误:其
res.render('index',{title:'Express'})
not
es.render('index',{title:'Express'})。我没有看到您试图如何处理路由中的url
wchat/wnode/users
。使用route handler
users.js更新您的问题
谢谢swaraj,因为复制粘贴可能会被删除。routes/users
在哪里?我已经更新了users.js。即使没有用户,默认路由索引也无法工作,并显示相同的错误:Thank,而是使用/wchat/wnode/users,我可以使用/user来运行路由。。如果我们有2-3级的目录结构,有没有办法定义缩短url。你可以在
/users
上做你想做的事,而不是像
/wchat/wnode/users
那样创建一个长url,谢谢,而是使用/wchat/wnode/users我可以使用/user来运行路由。。如果我们有2-3级目录结构,有没有办法定义缩短url。你可以在
/users
上做你想做的事,而不是像
/wchat/wnode/users
那样创建一个长url