使用以下服务器代码:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io');
// Set the environment variables we need.
ipaddress = process.env.OPENSHIFT_NODEJS_IP;
port = process.env.OPENSHIFT_INTERNAL_PORT || process.env.OPENSHIFT_NODEJS_PORT || 8080;
if (typeof ipaddress === "undefined") {
// Log errors on OpenShift but continue w/ 127.0.0.1 - this
// allows us to run/test the app locally.
console.warn('No OPENSHIFT_NODEJS_IP var, using 127.0.0.1');
ipaddress = "127.0.0.1";
};
app.get('/', function(req, res){
res.sendfile('index.html');
});
http.listen(process.env.OPENSHIFT_NODEJS_PORT, process.env.OPENSHIFT_NODEJS_IP, function(){
console.log('listening on *:' + port + ", " + ipaddress);
});
我只是试图在我的代码中包含socket.io模块,甚至没有初始化io,并且我的代码在尝试在Openshift上启动应用程序时出错。当我删除" var io = require(' socket.io');"我的应用程序启动正常。
当我通过SSH进入我的服务器空间并查看node_modules时,看起来Openshift似乎没有安装socketio,即使我已将它包含在我的包中。
这是我的package.json:
{
"name": "OpenShift-Sample-App",
"version": "1.0.0",
"description": "OpenShift Sample Application",
"keywords": [
"OpenShift",
"Node.js",
"application",
"openshift"
],
"author": {
"name": "OpenShift",
"email": "ramr@example.org",
"url": "http://www.openshift.com/"
},
"homepage": "http://www.openshift.com/",
"repository": {
"type": "git",
"url": "https://github.com/openshift/origin-server"
},
"engines": {
"node": ">= 0.6.0",
"npm": ">= 1.0.0"
},
"dependencies": {
"express": "^4.10.2",
"socket.io": "^1.3.7"
},
"devDependencies": {},
"bundleDependencies": [],
"private": true,
"main": "server.js"
}
在git push to Openshift期间,它表示包括socketio在内的所有软件包都安装正常。
我知道怎样才能让socketio模块在Openshift上正常运行?
答案 0 :(得分:0)
由于插入字符
,看起来旧的npm版本在npm安装时出现问题尝试在package.json
"dependencies": {
"express": "4.10.2",
"socket.io": "1.3.7"
},