Openshift node app error when restarting

时间秒杀一切 提交于 2019-12-12 03:24:17

问题


I have a node/socket.io chat app hosted on openshift, and while it starts correctly if i ssh into the server and do "node main.js" (where main.js is the server script that starts the chat), I can't start the app on the server by web interface, where it would go on automatically; If i just start the app by ssh, it would stop working as soon as i exit the terminal.

I get this error when starting the app by the web interface:

    Starting Node.js application...
    Application is already stopped.
    Warning! Could not start Node.js application!
    Failed to execute: 'control restart' for /var/lib/openshift/57003fbe7628e1491d00011e/nodejs

In case it's relevant, my package.json file is

{
  "name": "rainychat",
  "version": "1.0.0",
  "description": "rainychat, my chat app",
  "main": "main.js",
  "dependencies": {
    "express": "^4.13.4",
    "socket.io": "^1.4.5",
    "validator": "^5.1.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "JG",
  "license": "ISC"
}

And here you can see the files of the app by ftp:

I can't decode what that error means...

My main.js code

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.get('/', function (req, res) {
    res.sendFile(__dirname + '/chat.html'); // /home/redadmin/public_html/rainychat.com
    console.log('enviado');
});

app.set('port', process.env.OPENSHIFT_NODEJS_PORT || 8080);
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1');

http.listen(app.get('port'), app.get('ip'), function () {
    console.log('Listening on port ' + app.get('port'));
});
//... More code

回答1:


If you're creating a new Node project, start with npm init to create the package.json file. You can add the --auto option to give it safe defaults.

Remember, the JSON file must be valid JSON, so test it with jsonlint or a tool like an online validator.

Any dependencies your project has should be spelled out in the package file. This is done automatically with things like npm install express --save.



来源:https://stackoverflow.com/questions/36380606/openshift-node-app-error-when-restarting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!