node.js - 使用express js进行heroku部署没有发生

标签 node.js express heroku

我将 Node 项目部署到heroku,它显示应用程序错误

下面是 express 文件

var express = require('express'),
  http = require('http');
var bodyParser  = require('body-parser');
var app = express()
  .use(bodyParser.urlencoded())
  .use(express.static(__dirname + '/public'))
  .use('/node_modules',  express.static(__dirname + '/node_modules'));

以下是heroku的日志

2016-03-20T09:21:02.381628+00:00 heroku[web.1]: State changed from crashed to starting
2016-03-20T09:21:03.470949+00:00 heroku[web.1]: Starting process with command `npm start`
2016-03-20T09:21:06.258287+00:00 app[web.1]: 
2016-03-20T09:21:06.321039+00:00 app[web.1]:     ^
2016-03-20T09:21:06.258314+00:00 app[web.1]: > node server.js
2016-03-20T09:21:06.258312+00:00 app[web.1]: > mean-app@1.0.0 start /app
2016-03-20T09:21:06.258314+00:00 app[web.1]: 
2016-03-20T09:21:06.321038+00:00 app[web.1]:     throw err;
2016-03-20T09:21:06.321061+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:339:15)
2016-03-20T09:21:06.321032+00:00 app[web.1]: module.js:341
2016-03-20T09:21:06.321061+00:00 app[web.1]:     at Function.Module._load (module.js:290:25)
2016-03-20T09:21:06.321044+00:00 app[web.1]: 
2016-03-20T09:21:06.321062+00:00 app[web.1]:     at require (internal/module.js:16:19)
2016-03-20T09:21:06.321064+00:00 app[web.1]:     at Module._compile (module.js:413:34)
2016-03-20T09:21:06.321053+00:00 app[web.1]: Error: Cannot find module 'express'
2016-03-20T09:21:06.321064+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:422:10)
2016-03-20T09:21:06.321065+00:00 app[web.1]:     at Module.load (module.js:357:32)
2016-03-20T09:21:06.321063+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:1:77)
2016-03-20T09:21:06.321066+00:00 app[web.1]:     at Function.Module._load (module.js:314:12)
2016-03-20T09:21:06.321066+00:00 app[web.1]:     at Function.Module.runMain (module.js:447:10)
2016-03-20T09:21:06.321062+00:00 app[web.1]:     at Module.require (module.js:367:17)
2016-03-20T09:21:06.335202+00:00 app[web.1]: npm ERR! Linux 3.13.0-79-generic
2016-03-20T09:21:06.335744+00:00 app[web.1]: npm ERR! node v5.8.0
2016-03-20T09:21:06.328269+00:00 app[web.1]: 
2016-03-20T09:21:06.335562+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-03-20T09:21:06.336060+00:00 app[web.1]: npm ERR! npm  v3.7.3
2016-03-20T09:21:06.336389+00:00 app[web.1]: npm ERR! mean-app@1.0.0 start: `node server.js`
2016-03-20T09:21:06.336587+00:00 app[web.1]: npm ERR! 
2016-03-20T09:21:06.336281+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-03-20T09:21:06.336476+00:00 app[web.1]: npm ERR! Exit status 1
2016-03-20T09:21:06.336685+00:00 app[web.1]: npm ERR! Failed at the mean-app@1.0.0 start script 'node server.js'.
2016-03-20T09:21:06.336786+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-03-20T09:21:06.336880+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the mean-app package,
2016-03-20T09:21:06.337139+00:00 app[web.1]: npm ERR!     node server.js
2016-03-20T09:21:06.336968+00:00 app[web.1]: npm ERR! not with npm itself.
2016-03-20T09:21:06.337048+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-03-20T09:21:06.337580+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-03-20T09:21:06.337227+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-03-20T09:21:06.337319+00:00 app[web.1]: npm ERR!     npm bugs mean-app
2016-03-20T09:21:06.337402+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-03-20T09:21:06.341555+00:00 app[web.1]: 
2016-03-20T09:21:06.337500+00:00 app[web.1]: npm ERR!     npm owner ls mean-app
2016-03-20T09:21:06.341875+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-03-20T09:21:06.341966+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-03-20T09:21:07.158614+00:00 heroku[web.1]: State changed from starting to crashed
2016-03-20T09:21:07.137366+00:00 heroku[web.1]: Process exited with status 1
2016-03-20T09:21:59.871731+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=m-e-a-n.herokuapp.com request_id=c8663e92-89be-4105-a971-d42250ecc574 fwd="49.206.213.175" dyno= connect= service= status=503 bytes=
2016-03-20T09:22:00.525395+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=m-e-a-n.herokuapp.com request_id=f7c7eee7-ffac-4774-acda-5452eecfbd0d fwd="49.206.213.175" dyno= connect= service= status=503 bytes=

这是我的 package.json

{
  "name": "mean-app",
  "version": "1.0.0",
  "description": "to develop mean application",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/krthk2005/mean_project.git"
  },
  "keywords": [
    "test",
    "mean",
    "project"
  ],
  "author": "kartheek",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/krthk2005/mean_project/issues"
  },
  "homepage": "https://github.com/krthk2005/mean_project#readme",
  "dependencies": {
    "bcrypt": "^0.8.5"
  }
}

最佳答案

您必须在 package.json 中添加 expressbody-parser 作为依赖项。

如:

"dependencies": {
    "express":"*",
    "body-parser":"*",
    "bcrypt": "^0.8.5"
 }

因为 heroku 通过 npm install 安装依赖项,并且该命令会下载 package.json 中列出的所有包作为依赖项。

关于node.js - 使用express js进行heroku部署没有发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36112119/

相关文章:

mysql - 为了 Heroku,从 MySQL 切换到 PostgreSQL for Ruby on Rails

node.js - 运行 npm install get/bin/sh : 1: npm: not found

node.js - 转换 fastify-static 提供的文件的响应

javascript - 如何设置 Handlebars 布局目录?

node.js - 我是否实现了 NodesJS + Passport + RedisStore 的序列化和反序列化?

database - 什么是数据库缓存以及如何使用它?

angularjs - Bower install 是否需要在与 Bower.json 相同的文件夹中运行?

node.js - 时间戳范围之间的lodash _.filter时间戳?

javascript - 使用 ".create"时如何使用 Mongoose 添加到数组中的对象

sql - 使用 cloud 9 命令行更新查询在 Heroku 上不起作用