Reputation: 1241
I've installed express.js in specificed folder scoreboard, I'm trying to execute "npm start" in CLI, then I got error was:
0 info it worked if it ends with ok
1 verbose cli [ 'node', '/opt/rh/nodejs010/root/usr/bin/npm', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart [email protected]
6 info start [email protected]
7 verbose unsafe-perm in lifecycle true
8 info [email protected] Failed to exec start script
9 error [email protected] start: `node app.js`
9 error Exit status 8
10 error Failed at the [email protected] 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 ]
There content of app.js is:
/**
* 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'));
});
I had no idea how to fix it, I'm looking a solution how to run express in Openshift, Thanks!
Upvotes: 4
Views: 614
Reputation: 1411
I know it's been a long time since this issue was opened, but I could deploy it successfully to Openshift.
Like Thimoty Gu said, there were some problems in your app.js
. because some features you are using from Express are deprecated, what can impact to deploy an app to Openshift.
In Openshift I've had problems with very simple things, like setting the package.json with * instead of the right version of the dependency I wanted.
I did a few changes in your code without the routes file and it worked in my test. Basically, the result is:
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);
});
In summary, I just removed/commented your libraries that are not supported or are deprecated in Express. To use them now, you should include them from the new libraries that support them.
Hope it's somehow useful, even so long later.
Upvotes: 1