Openshift服务器服务暂时不可用

时间:2015-04-09 10:50:42

标签: node.js git mongodb mongoose openshift

创建了一个MEAN堆栈应用程序。 在我的server.js文件中添加mongoose并将其添加到openshift时,应用程序停止工作。表明 服务暂时无法使用。

server.js代码:

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var multer = require('multer'); 
var passport      = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var cookieParser  = require('cookie-parser');
var session       = require('express-session');
var mongoose      = require('mongoose');
var db = mongoose.connect('mongodb://localhost/myproject');

var UserSchema = new mongoose.Schema({
    firstname: String,
    lastname: String,
    email: String,
    username: String,
    password: String
});

var UserModel = mongoose.model('UserModel', UserSchema);

var ip = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
var port= process.env.OPENSHIFT_NODEJS_PORT || 3000;

app.listen(port, ip);

的package.json:

{
  "name": "MyProject",
  "version": "1.0.0",
  "description": "MyProject CS5610",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Pankaj Tripathi",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.12.2",
    "cookie-parser": "^1.3.4",
    "express": "^4.12.3",
    "express-session": "^1.10.4",
    "http": "0.0.0",
    "mongoose": "^3.8.25",
    "multer": "^0.1.8",
    "passport": "^0.2.1",
    "passport-local": "^1.0.0"
  }

}

rhc tail显示以下错误:

module.js:340     扔错了;           ^ 错误:找不到模块' /var/lib/openshift/552644dffcf933d46400014d/server.js'     在Function.Module._resolveFilename(module.js:338:15)     在Function.Module._load(module.js:280:25)     在Function.Module.runMain(module.js:497:10)     在启动时(node.js:119:16)     在node.js:902:3 [myproject-pankajt.rhcloud.com 552644dffcf933d46400014d]> LS app-deployments app-root git mongodb nodejs [myproject-pankajt.rhcloud.com 552644dffcf933d46400014d]>超时等待输入:自动注销 与myproject-pankajt.rhcloud.com的连接已关闭。

2 个答案:

答案 0 :(得分:0)

这句话完成了这项工作。

var connectionString = process.env.OPENSHIFT_MONGODB_DB_URL || 'mongodb://localhost/myproject';
mongoose.connect(connectionString)

答案 1 :(得分:-1)

更改

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },

"scripts": {
    "start": "server app.js"
  },
"engines": {
"node": ">= 0.6.0",
"npm": ">= 1.0.0"
}