Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying nodejs app with Open Shift PaaS

I'm starting with Open Shift PaaS and I picked a node.js app as my first try.

So far I'm getting a 503 when I try to access my app site.

I've tried:

  • Set my github repo,
  • set the ssh key at github and made Open Shift have it,
  • created a very simple app using express (I did install express by npm)
  • did commit and pushed all changes,
  • I did install rhc and ran rhc app restart -a nodejs

But I can't get it to work.

The rhc tail -a nodejs outputs:

DEBUG: Error: Cannot find module '/var/lib/openshift/531be41fe0b8cd3d12000003/app-root/runtime/repo/server.js'
    at Function._resolveFilename (module.js:337:11)
    at Function._load (module.js:279:25)
    at Array.0 (module.js:484:10)
    at EventEmitter._tickCallback (node.js:190:38)

DEBUG: Program node server.js exited with code 1

DEBUG: Starting child process with 'node server.js'

This is my app.js file:

var express = require('express')
var server = new express()
server.use(express.static(__dirname+"/public"))


server.get('/', function (request, response) {
    response.send(200)
})

server.listen(process.env.OPENSHIFT_NODEJS_PORT || 80)

EDIT

I've renamed app.js to server.js, did git add, commit and push, restarted app with rhc. but it's not working yet though.

like image 219
diegoaguilar Avatar asked Mar 09 '14 07:03

diegoaguilar


People also ask

What does OpenShift look for when running a NodeJS application?

By default, for a NodeJS application, OpenShift looks for a start script to execute. If there is no start script, OpenShift cannot decide what to do with our application code.

What is nodeshift and how does it work?

According to the Nodeshift module readme: Nodeshift is an opinionated command-line application and programmable API that you can use to deploy Node.js projects to OpenShift.

What port does node app run on?

The Red Hat and CentOS S2I images generally expose port 8080. This means that your Node app also needs to run on port 8080. You also need to make sure that your app is listening on all interfaces. Set your server listen address to 0.0.0.0, not “localhost” or “127.0.0.1”.

What is node Node JS?

Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.


1 Answers

You can name your main script whatever you want, as long as the contents of your package.json file accurately describes your recommended server init process

I've written up a blog post that outlines the two main steps for getting your Node.js project to run on OpenShift:

  1. Update your package.json file, documenting your server init process (main, scripts.start).
  2. Adapt your code to rely on environment variables for runtime configuration details: server ip, port, domain name, db passwords, and other custom tokens

Make sure to document your preferred deployment process in your project's README file as well

like image 145
ʀɣαɳĵ Avatar answered Oct 17 '22 05:10

ʀɣαɳĵ