在Heroku上托管node.js应用程序时输入错误

时间:2012-12-12 14:49:20

标签: node.js heroku express

我的node.js应用程序带有依赖项

{
  "name": "application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app"
  },
  "dependencies": {
    "express": ">=2.2.0",
    "jade": "*",
    "stylus": "*",
    "mongodb": ">= 0.9.6-7"
  }

}

它在我的localhost上工作正常

当我在heroku上托管我的节点应用程序时,我收到以下错误。

  

TypeError:对象#没有方法'randomBytes'       在Object.uid(/app/node_modules/express/node_modules/connect/lib/utils.js:121:17)       在MemoryStore.generate(/app/node_modules/express/node_modules/connect/lib/middleware/session.js:204:27)       at generate(/app/node_modules/express/node_modules/connect/lib/middleware/session.js:288:13)       在Object.session [作为句柄](/app/node_modules/express/node_modules/connect/lib/middleware/session.js:297:7)       在下一个(/app/node_modules/express/node_modules/connect/lib/proto.js:190:15)       在Object.cookieParser [作为句柄](/app/node_modules/express/node_modules/connect/lib/middleware/cookieParser.js:60:5)       在下一个(/app/node_modules/express/node_modules/connect/lib/proto.js:190:15)       在Object.expressInit [作为句柄](/app/node_modules/express/lib/middleware.js:31:5)       在下一个(/app/node_modules/express/node_modules/connect/lib/proto.js:190:15)       在Object.query [作为句柄](/app/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)

我试图逐个删除行,然后到达我删除的地方

app.use(express.session({ secret:'yodawgyo' }));

该应用程序正在提供“Hello World”响应。 请参阅下面的完整代码。

var express = require('express');
var crypto = require('crypto');//for gravatar

var passport = require('passport')
  , OpenIDStrategy = require('passport-openid').Strategy
  , GoogleStrategy = require('passport-google').Strategy
  , AOLStrategy = require('passport-aol').Strategy
  , YahooStrategy = require('passport-yahoo').Strategy;;



passport.serializeUser(function(user, done) { 
  done(null, user);
});

passport.deserializeUser(function(obj, done) {
  done(null, obj);
});

var app = module.exports = express();

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.cookieParser());


//NO ISSUES WITH HEROKU IF I COMMENTED BELOW LINE   
  app.use(express.session({ secret:'yodawgyo' }));


  app.use(app.router);

});

app.get('/', function(req, res) {
  res.send("Hello World");
});

app.listen(process.env.PORT || 5000, function() {
  console.log("listening on 5000");
});

请帮帮我。

1 个答案:

答案 0 :(得分:7)

我遇到了同样的问题。它通过向package.json添加“engines”块来解决,它引导Heroku使用特定版本的节点和npm。很可能你使用的节点版本比Heroku默认值0.4.7

更新

请参阅https://devcenter.heroku.com/articles/nodejs-support#versions