Search code examples
node.jsopenshiftnode-red

node red openshift user directory


I am using Openshift to create my node-red app. I want to store my nodes in the user directory of Openshift environment variable which is process.env.OPENSHIFT_DATA_DIR but when I build and run my app I see this error from Openshift deployment log:

    Environment: 
    DEV_MODE=false
    NODE_ENV=production
    DEBUG_PORT=5858
Launching via npm...
npm info it worked if it ends with ok
npm info using npm@2.15.1
npm info using node@v4.6.2
npm info prestart node-red-app@
npm info start node-red-app@

> node-red-app@ start /opt/app-root/src
> node app.js

Potentially unhandled rejection [1] Error: Property 'userDir' is read-only

and here is my app.js:

var http = require('http');
var express = require("express");
var RED = require("node-red");


// Create an Express app
var app = express();

// Add a simple route for static content served from 'public'
app.use("/",express.static("public"));

// Create a server
var server = http.createServer(app);

// Create the settings object - see default settings.js file for other options
var settings = {
    nodesDir: process.env.OPENSHIFT_DATA_DIR,
    httpAdminRoot:"/",
    httpNodeRoot: "/api",
    userDir: process.env.OPENSHIFT_DATA_DIR,
    uiPort: 8080,
    functionGlobalContext: { }    // enables global context
};

// Initialise the runtime with a server and settings
RED.init(server,settings);

// Serve the editor UI from /red
app.use(settings.httpAdminRoot,RED.httpAdmin);

// Serve the http nodes UI from /api
app.use(settings.httpNodeRoot,RED.httpNode);

server.listen(8080);

// Start the runtime
RED.start();

should I define environment variable separately in Openshift dashboard? Thanks.


Solution

  • I solved it with defining this environment variable in deployment dashboard: OPENSHIFT_DATA_DIR as app-root/data. There was no problem with my node.js code.