当我们从nodejs root运行server.js文件时,我们遇到错误"找不到模块路由"。这是一个从Ubuntu nodejs环境执行的简单快速框架项目。
服务器/ configure.js
<div class="bar-logout">
<span>
<span class="logout"><div class="logout-icon"></div>LOGOUT</span>
</span>
</div>
根/ server.js
var path = require('path'),routes = require('routes'),
exphbs = require('express-handlebars'),
express = require('express'),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
morgan = require('morgan'),
methodOverride = require('method-override'),
errorHandler = require('errorhandler');
module.exports = function(app) {
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({'extended':true}));
app.use(bodyparser.json());
app.use(methodOverride());
app.use(cookieParser('some-secret-value-here'));
routes(app);//moving the routes to routes folder.
app.use('/public/', express.static(path.join(__dirname, '../public')));
if ('development' === app.get('env')) {
app.use(errorHandler());
}
return app;
};
答案 0 :(得分:0)
如果routes.js
应该是你自己的路由模块,那么看起来错误可能来自这行代码而且它告诉你它找不到routes.js模块文件:
routes = require('routes')
并且,这不起作用,因为您尝试加载没有正确路径名的本地模块。如果未指定路径,则它会尝试加载全局或内置模块。如果该模块位于当前目录中,则可以使用:
routes = require('./routes')