gpt4 book ai didi

javascript - Nodejs 项目无法在 heroku 中启动

转载 作者:行者123 更新时间:2023-11-30 20:20:22 25 4
gpt4 key购买 nike

我正在尝试在 heroku.com 中部署 nodejs 应用程序。我成功推送了 heroku master 中的代码。当我尝试访问此应用程序时,它显示以下错误。

enter image description here

我还检查了日志,发现了以下错误。

2018-07-25T06:17:36.798787+00:00 heroku[web.1]: Starting process with command `npm start`
2018-07-25T06:17:39.066859+00:00 app[web.1]:
2018-07-25T06:17:39.066885+00:00 app[web.1]: > nodegigapi@0.0.0 start /app
2018-07-25T06:17:39.066887+00:00 app[web.1]: > node ./bin/www
2018-07-25T06:17:39.066888+00:00 app[web.1]:
2018-07-25T06:17:39.138914+00:00 app[web.1]: module.js:549
2018-07-25T06:17:39.138917+00:00 app[web.1]: throw err;
2018-07-25T06:17:39.138918+00:00 app[web.1]: ^
2018-07-25T06:17:39.138920+00:00 app[web.1]:
2018-07-25T06:17:39.138921+00:00 app[web.1]: Error: Cannot find module '/app/bin/www'
2018-07-25T06:17:39.138923+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:547:15)
2018-07-25T06:17:39.138924+00:00 app[web.1]: at Function.Module._load (module.js:474:25)
2018-07-25T06:17:39.138925+00:00 app[web.1]: at Function.Module.runMain (module.js:693:10)
2018-07-25T06:17:39.138926+00:00 app[web.1]: at startup (bootstrap_node.js:191:16)
2018-07-25T06:17:39.138927+00:00 app[web.1]: at bootstrap_node.js:612:3
2018-07-25T06:17:39.144035+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-07-25T06:17:39.144315+00:00 app[web.1]: npm ERR! errno 1
2018-07-25T06:17:39.145314+00:00 app[web.1]: npm ERR! nodegigapi@0.0.0 start: `node ./bin/www`
2018-07-25T06:17:39.145428+00:00 app[web.1]: npm ERR! Exit status 1
2018-07-25T06:17:39.145607+00:00 app[web.1]: npm ERR!
2018-07-25T06:17:39.145751+00:00 app[web.1]: npm ERR! Failed at the nodegigapi@0.0.0 start script.
2018-07-25T06:17:39.149954+00:00 app[web.1]:
2018-07-25T06:17:39.145852+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-07-25T06:17:39.150091+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-07-25T06:17:39.150165+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-07-25T06_17_39_147Z-debug.log
2018-07-25T06:17:39.195926+00:00 heroku[web.1]: Process exited with status 1
2018-07-25T06:17:39.212995+00:00 heroku[web.1]: State changed from starting to crashed
2018-07-25T06:17:39.215182+00:00 heroku[web.1]: State changed from crashed to starting
2018-07-25T06:17:41.663113+00:00 heroku[web.1]: Starting process with command `npm start`
2018-07-25T06:17:43.846000+00:00 app[web.1]:
2018-07-25T06:17:43.846025+00:00 app[web.1]: > node ./bin/www
2018-07-25T06:17:43.846023+00:00 app[web.1]: > nodegigapi@0.0.0 start /app
2018-07-25T06:17:43.846027+00:00 app[web.1]:
2018-07-25T06:17:43.920839+00:00 app[web.1]: module.js:549
2018-07-25T06:17:43.920842+00:00 app[web.1]: throw err;
2018-07-25T06:17:43.920843+00:00 app[web.1]: ^
2018-07-25T06:17:43.920847+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:547:15)
2018-07-25T06:17:43.920844+00:00 app[web.1]:
2018-07-25T06:17:43.920845+00:00 app[web.1]: Error: Cannot find module '/app/bin/www'
2018-07-25T06:17:43.920848+00:00 app[web.1]: at Function.Module._load (module.js:474:25)
2018-07-25T06:17:43.920850+00:00 app[web.1]: at startup (bootstrap_node.js:191:16)
2018-07-25T06:17:43.920849+00:00 app[web.1]: at Function.Module.runMain (module.js:693:10)
2018-07-25T06:17:43.920852+00:00 app[web.1]: at bootstrap_node.js:612:3
2018-07-25T06:17:43.926342+00:00 app[web.1]: npm ERR! errno 1
2018-07-25T06:17:43.926056+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-07-25T06:17:43.927330+00:00 app[web.1]: npm ERR! nodegigapi@0.0.0 start: `node ./bin/www`
2018-07-25T06:17:43.927429+00:00 app[web.1]: npm ERR! Exit status 1
2018-07-25T06:17:43.927591+00:00 app[web.1]: npm ERR!
2018-07-25T06:17:43.927697+00:00 app[web.1]: npm ERR! Failed at the nodegigapi@0.0.0 start script.
2018-07-25T06:17:43.927800+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-07-25T06:17:43.934451+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-07-25T06_17_43_929Z-debug.log
2018-07-25T06:17:43.934236+00:00 app[web.1]:
2018-07-25T06:17:43.934368+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:

下面是我的项目结构。我正在通过 npm start 命令启动应用程序。和 app.js 有我的服务器代码。在公共(public)文件夹中,我有 angular js 1 代码。

app.js

app.use('/api', googleRouter);

app.listen(2020, function () {
console.log('Server strated on port 2020 !');
});

module.exports = app;

enter image description here

bin/www

#!/usr/bin/env node

/**
* Module dependencies.
*/

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

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

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

/**
* Create HTTP server.
*/

var server = http.createServer(app);

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

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* 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;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}

有人可以指导我吗?

最佳答案

您需要创建文件 Procfile 上传到 heroku,您可以尝试以下操作,或者您会看到:How to Deploy a Node.js App to Heroku

//Procfile
web: node app.js

//app.js
var express = require('express');
var app = express();
var http = require('http').Server(app);

app.get('/',function(req,res){
res.send('Hello');
})

http.listen(process.env.PORT || 8888, function(){
console.log('listening on *:8888');
});

关于javascript - Nodejs 项目无法在 heroku 中启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51512273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com