我是NodeJS的新手,我无法运行旧项目。 这是错误信息......
错误:大多数中间件(如压缩)不再与Express捆绑在一起,必须单独安装。请参阅https://github.com/senchalabs/connect#middleware。
这是server.js的代码
/*** Module dependencies.*/
/*jshint loopfunc: true */
var express = require('express'),
fs = require('fs'),
passport = require('passport'),
logger = require('mean-logger');
//Load configurations
var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development',
config = require('./config/config'),
auth = require('./config/middlewares/authorization'),
mongoose = require('mongoose');
//Bootstrap db connection
var db = mongoose.connect(config.db);
var register_models = require('./app/register_models');
register_models();
//Bootstrap models
var models_path = __dirname + '/app/models';
var walk = function(path) {
fs.readdirSync(path).forEach(function(file) {
var newPath = path + '/' + file;
var stat = fs.statSync(newPath);
if (stat.isFile()) {
if (/(.*)\.(js|coffee)/.test(file)) {
require(newPath);
}
} else if (stat.isDirectory()) {
walk(newPath);
}
});
};
walk(models_path);
//bootstrap passport config
require('./config/passport')(passport);
var app = express();
//express settings
require('./config/express')(app, passport, db);
//Bootstrap routes
require('./config/routes')(app, passport, auth);
//Start the app by listening on <port>
var port = process.env.PORT || config.port;
app.listen(port);
console.log('Express app started on port ' + port);
//Initializing logger
logger.init(app, passport, mongoose);
//expose app
exports = module.exports = app;
答案 0 :(得分:3)
这是因为快递4.xx,如果您的项目文件夹中的运行npm install命令和package.json具有依赖性,如“express”:“^ 4.10.6”或“express”:“*”,其中转将安装最新版的快递。它(表达4.x.x)不会让您的旧应用程序(用快速3.x.x或&lt;版本编写)运行。
这个问题可以通过安装express&lt; 4.x.x例如:
npm install express@3.x.x
或安装登录节点控制台的每个缺失模块(与上述缺失完全相同)
或者这里是关于从express 3.x.x迁移到4.x.x
的好文章快乐帮助!