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:
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.
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.
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.
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”.
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.
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:
package.json
file, documenting your server init process (main, scripts.start).Make sure to document your preferred deployment process in your project's README file as well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With