To deploy an existing project into openshift you need to modify your
package.json and server.json files:
package.json
- Add the server.js file to the main key
Add a start script in the scripts key
"main": "server.js",
"scripts": {
"start": "node server.js",
}
example
{
"name": "to-do",
"version": "1.0.0",
"description": "Simple todo app",
"main": "server.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"node",
"angular"
],
"dependencies" : {
"express" : "~4.7.2",
"mongoose" : "~3.6.2",
"morgan" : "~1.2.2",
"body-parser": "~1.5.2",
"method-override": "~2.1.2"
},
"author": "[email protected]",
"license": "MIT"
}
server.js
- Add dynamic port from the openshift env
Add dynamic IP from the openshift env
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
app.listen(server_port, server_ip_address, function () {
console.log( "Listening on " + server_ip_address + ", server_port " + server_port );
});
Now you can use the rhc --from-code flag to deploy a project from existing code
rhc app create appName nodejs-0.10 -s --from-code=https://github.com/username/app.git
UPDATE
If you're using mongodb you need to update your server.js file
if(process.env.OPENSHIFT_MONGODB_DB_PASSWORD){
connection_string = process.env.OPENSHIFT_MONGODB_DB_USERNAME + ":" +
process.env.OPENSHIFT_MONGODB_DB_PASSWORD + "@" +
process.env.OPENSHIFT_MONGODB_DB_HOST + ':' +
process.env.OPENSHIFT_MONGODB_DB_PORT + '/' +
process.env.OPENSHIFT_APP_NAME;
config.db.mongo.url = connection_string;
}
Hope this helps.