使用express js的heroku部署没有发生

Kar*_*k s 0 heroku node.js express

我将节点项目部署到heroku,它说应用程序错误

以下是快递文件

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'));
Run Code Online (Sandbox Code Playgroud)

以下是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=
Run Code Online (Sandbox Code Playgroud)

这是我的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"
  }
}
Run Code Online (Sandbox Code Playgroud)

Zee*_*mon 8

你将不得不增加expressbody-parserpackage.json为依赖.

如:

"dependencies": {

`"express":"*",`

`"body-parser":"*",`

`"bcrypt": "^0.8.5"`
Run Code Online (Sandbox Code Playgroud)

}

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

  • @ZeeshanHassanMemon,您的评论立即对我有用,谢谢。 (2认同)