2016-02-19 144 views
0

我在服務器上收到此錯誤,因爲我對啓動腳本有不同的結構(webstorm配置)。打開移動node.js - 使其在啓動時運行不同的啓動腳本

Error: Cannot find module '/var/lib/openshift/56c74bc61a003e5c2200015e/app-root/runtime/repo/server.js' 
    at Function.Module._resolveFilename (module.js:325:15) 
    at Function.Module._load (module.js:276:25) 
    at Function.Module.runMain (module.js:441:10) 
    at startup (node.js:134:18) 
    at node.js:962:3 
DEBUG: Program node server.js exited with code 1 
DEBUG: Starting child process with 'node server.js' 

我的package.json是(我已經添加了 「主」: 「./bin/www」 手動)

{ 
    "name": "app", 
    "version": "0.0.0", 
    "private": true, 
    "scripts": { 
    "start": "node ./bin/www" 
    }, 
    "main": "./bin/www", 
    "dependencies": { 
    "body-parser": "~1.13.2", 
    "cookie-parser": "~1.3.5", 
    "debug": "~2.2.0", 
    "express": "~4.13.1", 
    "jade": "~1.11.0", 
    "morgan": "~1.6.1", 
    "serve-favicon": "~2.3.0" 
    } 
} 

請指教,使上面的配置運行開放轉變。

編輯

實際添加"main": "./bin/www"給這個錯誤

DEBUG: Starting child process with 'node ./bin/www' 
Port 8080 is already in use 
DEBUG: Program node ./bin/www exited with code 1 
DEBUG: Starting child process with 'node ./bin/www' 
Port 8080 is already in use 
DEBUG: Program node ./bin/www exited with code 1 
DEBUG: Starting child process with 'node ./bin/www' 
Port 8080 is already in use 
DEBUG: Program node ./bin/www exited with code 1 
DEBUG: Starting child process with 'node ./bin/www' 

我的WWW文件

var port = normalizePort(process.env.OPENSHIFT_NODEJS_PORT || '3000'); 
app.set('port', port); 

/** 
* Normalize a port into a number, string, or false. 
*/ 

function normalizePort(val) { 
    var port = parseInt(val, 10); 

    if (isNaN(port)) { 
    // named pipe 
    return val; 
    } 

    if (port >= 0) { 
    // port number 
    return port; 
    } 

    return false; 
} 

回答

0

Openshift開始 'server.js' 的文件是默認的。您可以通過將use_npm文件添加到openshift的標記目錄中來避免這種情況。或者您可以將您的www文件內容複製到server.js並從此開始。

實施例的內容:

#!/usr/bin/env node 

/** 
* Module dependencies. 
*/ 

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

/** 
* Get port from environment and store in Express. 
*/ 

var port = normalizePort(process.env.OPENSHIFT_NODEJS_PORT || '3000'); 
app.set('port', port); 
var ip = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"; 
app.set('ip', ip); 

/** 
* Create HTTP server. 
*/ 

var server = http.createServer(app); 

/** 
* Listen on provided port, on all network interfaces. 
*/ 

server.listen(port, ip);