将Node.js MEAN应用程序部署到Heroku的问题

时间:2016-07-31 23:24:55

标签: node.js deployment mongoose mean-stack heroku-toolbelt

我的应用程序在本地工作,结构如下:

new IteratorDocumentSource("Hello World!".iterator) with PunctuationRemover

部署到heroku会导致应用程序错误。日志似乎表明bcrypt依赖和一些Mongoose模块的问题。我是否需要使用类似MongoLabs的东西来为我的应用程序在Heroku上工作?另外,我对package.json有些困惑,我不确定我是否正确实现了它。我的根目录和客户端目录以及我的服务器目录中都有一个package.json。

root中的

package.json:

MyApp
  >package.json
  >npm-debug.log
  >readme.md
  >client
    >app
    >node_modules
    >public
    >views
    >bower.json
    >Gruntfile.js
    >package.json
  >server
    >config
    >models
    >node_modules
    >routes
    >app.js
    >package.json

/ server中的package.json:

{
  "name": "****",
  "version": "1.0.0",
  "description": "****",
  "engines": {
    "node": "4.4.7"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "cd server && node app.js"
  },
  "author": "*****",
  "license": "ISC"
}

和/ client中的package.json:

{
  "name": "*****",
  "version": "1.0.0",
  "description": "******",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "******",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^0.8.5",
    "body-parser": "^1.13.2",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.3.5",
    "ejs": "^2.3.3",
    "express": "^4.13.1",
    "express-session": "^1.11.3",
    "mongoose": "^4.1.0",
    "mongoskin": "^1.3.20",
    "morgan": "^1.6.1",
    "passport": "^0.2.2",
    "passport-local": "^1.0.0"
  }
}

heroku日志:

{
  "name": "****",
  "version": "1.0.0",
  "description": "******",
  "main": "Gruntfile.js",
  "directories": {
    "test": "tests"
  },
  "dependencies": {
    "grunt": "^0.4.5"
  },
  "devDependencies": {
    "grunt-contrib-concat": "^0.5.1",
    "grunt-contrib-watch": "^0.6.1"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  }
}

1 个答案:

答案 0 :(得分:0)

解决。原来是bcrypt依赖的问题。通过.gitignore我的node_modules并在heroku服务器端安装依赖项,现在一切正常。