nodejs项目本地环境搭建问题,求各路高手大神解答~
发布于 1 天前 作者 woaizimmy 158 次浏览 来自 问答

nodejs版本v4.4.1 Python版本2.7.10 MongoDB服务已启动 Robomongo已连接上数据库并且已在代码中写好连接配置 npm install 下载依赖包之后,启动服务 然后,问题来了,如下: 求解怎么解决?求解怎么解决?求解怎么解决?

e:\wamp\www\magnet-zone-portal>node magnet-zone-portal-server.js server environment: dev e:\wamp\www\magnet-zone-portal\node_modules\express\lib\application.js:209 throw new TypeError(‘app.use() requires middleware functions’); ^

TypeError: app.use() requires middleware functions at EventEmitter.use (e:\wamp\www\magnet-zone-portal\node_modules\express\lib\application.js:209:11) at Object.<anonymous> (e:\wamp\www\magnet-zone-portal\magnet-zone-portal-server.js:65:5) at Module._compile (module.js:409:26) at Object.Module._extensions…js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:139:18) at node.js:968:3

4 回复

不是提示express有问题嘛,贴express那块代码吧

@ncuzp express是npm install下载的,提示是209行,下面是代码:

/**

  • Proxy Router#use() to add middleware to the app router.
  • See Router#use() documentation for details.
  • If the fn parameter is an express app, then it will be
  • mounted at the route specified.
  • @public */

app.use = function use(fn) { var offset = 0; var path = ‘/’;

// default path to ‘/’ // disambiguate app.use([fn]) if (typeof fn !== ‘function’) { var arg = fn;

while (Array.isArray(arg) && arg.length !== 0) {
  arg = arg[0];
}

// first arg is the path
if (typeof arg !== 'function') {
  offset = 1;
  path = fn;
}

}

var fns = flatten(slice.call(arguments, offset));

if (fns.length === 0) { throw new TypeError(‘app.use() requires middleware functions’); }

// setup router this.lazyrouter(); var router = this._router;

fns.forEach(function (fn) { // non-express app if (!fn || !fn.handle || !fn.set) { return router.use(path, fn); }

debug('.use app under %s', path);
fn.mountpath = path;
fn.parent = this;

// restore .app property on req and res
router.use(path, function mounted_app(req, res, next) {
  var orig = req.app;
  fn.handle(req, res, function (err) {
    req.__proto__ = orig.request;
    res.__proto__ = orig.response;
    next(err);
  });
});

// mounted an app
fn.emit('mount', this);

}, this);

return this; };

if (fns.length === 0) { throw new TypeError(‘app.use() requires middleware functions’); }

结果:问题解决了。 解决方法:项目开发者发给我他那边的node modules,我这边直接用。 原因:项目是别人开发的,我下载代码之后,直接在本地npm install所需依赖库,配置好数据库等,启动服务,一直提示上面说到的错误信息。

回到顶部