当前位置 : 主页 > 网页制作 > Nodejs >

node.js – 如何修复Openshift中的express.js错误?

来源:互联网 收集:自由互联 发布时间:2021-06-16
我已经在特定的文件夹记分板中安装了express.js,我正在尝试在CLI中执行“npm start”,然后我得到的错误是: 0 info it worked if it ends with ok1 verbose cli [ 'node', '/opt/rh/nodejs010/root/usr/bin/npm', 'sta
我已经在特定的文件夹记分板中安装了express.js,我正在尝试在CLI中执行“npm start”,然后我得到的错误是:

0 info it worked if it ends with ok
1 verbose cli [ 'node', '/opt/rh/nodejs010/root/usr/bin/npm', 'start' ]
2 info using npm@1.3.24
3 info using node@v0.10.25
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart application-name@0.0.1
6 info start application-name@0.0.1
7 verbose unsafe-perm in lifecycle true
8 info application-name@0.0.1 Failed to exec start script
9 error application-name@0.0.1 start: `node app.js`
9 error Exit status 8
10 error Failed at the application-name@0.0.1 start script.
10 error This is most likely a problem with the application-name package,
10 error not with npm itself.
10 error Tell the author that this fails on your system:
10 error     node app.js
10 error You can get their info via:
10 error     npm owner ls application-name
10 error There is likely additional logging output above.
11 error System Linux 2.6.32-504.3.3.el6.x86_64
12 error command "node" "/opt/rh/nodejs010/root/usr/bin/npm" "start"
13 error cwd /var/lib/openshift/54d99b5f5973ca0a11000120/app-root/runtime/repo/Scoreboard/scoreboard
14 error node -v v0.10.25
15 error npm -v 1.3.24
16 error code ELIFECYCLE
17 verbose exit [ 1, true ]

app.js的内容是:

/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var app = express();

// all environments
//app.set('port', process.env.PORT || 3000);

app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080); 
app.set('ipaddr', process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1");

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

我不知道如何修复它,我正在寻找一个如何在Openshift中运行express的解决方案,谢谢!

我知道这个问题已经打开了很长时间,但我可以将它成功部署到Openshift.

就像Thimoty Gu所说,你的app.js有一些问题.因为您在Express中使用的某些功能已被弃用,因此将应用程序部署到Openshift会产生什么影响.

在Openshift中,我遇到了一些非常简单的问题,例如将package.json设置为*而不是我想要的依赖项的正确版本.

我在没有routes文件的情况下对代码进行了一些更改,它在我的测试中有效.基本上,结果是:

的package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies" : {
    "express" : "4.9.5"   //it's important to set a version, instead of using *
  }
}

server.js

/**
 * Module dependencies.
 */

var express = require('express')
  //, routes = require('./routes')
  //, user = require('./routes/user')
  , http = require('http')
  , path = require('path');

var app = express();

// all environments
//app.set('port', process.env.PORT || 3000);

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
//app.use(express.favicon());
//app.use(express.logger('dev'));
//app.use(express.bodyParser());
//app.use(express.methodOverride());
//app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
//if ('development' == app.get('env')) {
//  app.use(express.errorHandler());
//}

app.get('/', function(req, res, err) {
	res.send("You have accessed page / (root)");
});

app.get('/users', function(req, res, err) {
	res.send("You have accessed page /users (users)");
});


var port = process.env.OPENSHIFT_NODEJS_PORT || 8080; 
var address = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";

console.log("Port: " + port);
console.log("Address: " + address);

var server = app.listen(port, address, function() {
	console.log('Express server listening on port ' + port);
});

总之,我刚刚删除/评论了不支持或在Express中不推荐使用的库.要立即使用它们,您应该从支持它们的新库中包含它们.

希望它在某种程度上有用,即使这么久以后.

网友评论