2017-02-26 55 views
1

我正在使用Openshift创建我的节点红色应用程序。 我想我的节点存储在Openshift环境变量,它是process.env.OPENSHIFT_DATA_DIR的用户目录,但是当我建立并运行我的应用我看到Openshift部署日志此错误:node.js openshift用户目录

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 [email protected] 
npm info using [email protected] 
npm info prestart [email protected] 
npm info start [email protected] 

> [email protected] start /opt/app-root/src 
> node app.js 

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

,这里是我的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(); 

我应该在Openshift仪表板中分别定义环境变量吗? 谢谢。

回答

1

我通过在部署仪表板中定义这个环境变量来解决它: OPENSHIFT_DATA_DIR as app-root/data。 我的node.js代码没有问题。