应用程序无法启动

应用程序无法启动

本文介绍了应用程序无法启动(端口8080)不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的node.js应用程序(具有express和mongoose)部署到openshift,但我无法这样做.该应用程序可以在我的本地环境中完美运行.

I am trying to deploy my node.js application (with express and mongoose) to openshift and I am not able to do so. The application works perfectly on my local environment.

我的入口点是文件/bin/www

my entry point is the file /bin/www

我将其作为package.json文件中此行的openshift入口点(每个):

I establish this as the entry point on openshift with this line in the package.json file (per this thread):

"main": "bin/www",

我已确保按照如下指南使用环境变量设置mongodb连接:

I have made sure to set my mongodb connection using environment variables according to the guide like so:

// default to a localhost configuration:
var mongoConnectionString = 'mongodb://127.0.0.1/code-blog';

// if OPENSHIFT env variables are present, use the available connection info:
if (process.env.OPENSHIFT_MONGODB_DB_PASSWORD) {
  mongoConnectionString = process.env.OPENSHIFT_MONGODB_DB_USERNAME + ":" +
  process.env.OPENSHIFT_MONGODB_DB_PASSWORD + "@" +
  process.env.OPENSHIFT_MONGODB_DB_HOST + ':' +
  process.env.OPENSHIFT_MONGODB_DB_PORT + '/' +
  process.env.OPENSHIFT_APP_NAME;
}

mongoose.connect(mongoConnectionString);

我得到的错误是:

remote: Waiting for application port (8080) become available ...
remote: Application 'codeblog' failed to start (port 8080 not available)
remote: -------------------------
remote: Git Post-Receive Result: failure
remote: Activation status: failure
remote: Activation failed for the following gears:
remote: 558a25bd5973ca7a74000162 (Error activating gear: CLIENT_ERROR: Failed to
 execute: 'control start' for /var/lib/openshift/558a25bd5973ca7a74000162/nodejs

remote: #<IO:0x00000000b49380>
remote: #<IO:0x00000000b49308>
remote: )
remote: Deployment completed with status: failure
remote: postreceive failed
To ssh://[email protected]/~/git/codebl
og.git/
   29635a8..7a0e926  master -> master

这对我来说很奇怪,因为我没有在任何地方指定端口8080.实际上,默认端口是在此处指定的:

This is peculior to me because I do not specify port 8080 anywhere. In fact, the default port is specified here:

var port = normalizePort(process.env.OPENSHIFT_NODEJS_PORT || "3000");
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";

app.set('port', port);

var server = http.createServer(app);

我不确定从这儿去哪里.我似乎没有足够的信息来确定下一步.

I am not really sure where to go from here. I don't seem to have enough information to determine my next step.

我添加了一些日志记录以测试该端口在哪个端口上运行,但是该日志记录语句永远不会运行.这是代码

[edit]I added some logging to test what port this is running on, but the logging statement is never run. Here is the code

console.log("TEST TEST TEST");

var app = require('../app');
var debug = require('debug')('ProjectTemplate:server');
var http = require('http');

var port = normalizePort(process.env.OPENSHIFT_NODEJS_PORT || "3000");
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";

console.log("PORT: ", port);

并输出

TEST TEST TEST
module.js:340
    throw err;
    ^
Error: Cannot find module './routes/logIn'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/var/lib/openshift/558a25bd5973ca7a74000162/app-root/           runtime/repo/app.js:26:13)

TEST TEST TEST来自入口点文件开头的日志记录语句.在到达console.log("PORT: ", port);之前似乎有些故障,这很可能与建立MongoDb连接的app.js有关.

TEST TEST TEST is from a logging statement at the beginning of the entry point file. Something seems to fail before it hits the console.log("PORT: ", port); It is probable that this is something to do with app.js where the MongoDb connection is made.

[/edit]

推荐答案

该错误原来是与端口无关的通用错误.显然,如果出现致命的JavaScript错误,它会显示此消息.

The error turned out to be a generic error that had nothing to do with the port. Apparently, if there is any fatal javascript error, it gives this message.

这篇关于应用程序无法启动(端口8080)不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 02:38