将Node.js应用程序部署到Heroku。错误NPM_CONFIG_LOGLEVEL =错误

时间:2017-04-28 19:21:04

标签: node.js meteor heroku github

我正在heroku上部署我的node.js应用程序但是当我运行我的应用程序时它显示我的应用程序错误,当我检查我的日志文件时,我发现NPM_CONFIG_LOGLEVEL =错误

我的package.json文件是:

{
  "name": "wework-1",
  "version": "1.0.0",
  "description": "We Work Meteor, a job board and developer directory for Meteor specific work https://www.weworkmeteor.com",
  "main": "",
  "engines": {
    "node": "= 4.5.0",
    "npm": "= 3.9.6"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "lint": "eslint .",
    "pretest": "npm run lint --silent"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/rohitchaudhary701/wework-1.git"
  }
}

我的日志文件是:

-----> Node.js app detected
-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_PRODUCTION=true
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
-----> Installing binaries
       engines.node (package.json):  = 4.5.0
       engines.npm (package.json):   = 3.9.6

       Resolving node version = 4.5.0 via semver.io...
       Downloading and installing node 4.5.0...
       Resolving npm version = 3.9.6 via semver.io...
       Downloading and installing npm 3.9.6 (replacing version 2.15.9)...
-----> Restoring cache
       Loading 2 from cacheDirectories (default):
       - node_modules
       - bower_components (not cached - skipping)
-----> Building dependencies
       Installing node modules (package.json)
-----> Caching build
       Clearing previous node cache
       Saving 2 cacheDirectories (default):
       - node_modules
       - bower_components (nothing to cache)
-----> Build succeeded!
 !     This app may not specify any way to start a node process
       https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type
-----> Discovering process types
       Procfile declares types     -> (none)
       Default types for buildpack -> web
-----> Compressing...
       Done: 12.7M
-----> Launching...
       Released v6
       https://whispering-cliffs-66861.herokuapp.com/ deployed to Heroku

应用网址为https://whispering-cliffs-66861.herokuapp.com/

4 个答案:

答案 0 :(得分:1)

从您的日志:

  

此应用可能未指定任何启动节点进程的方法

您可能需要做两件事:

  1. start
  2. 中添加package.json脚本
  3. 确保您收听process.env.PORT
  4. 中的端口

    看一下这个例子:

    请参阅package.json和start脚本:

      "scripts": {
        "start": "node server.js"
      },
    

    请参阅:

    并查看端口号初始化:

    const port = process.env.PORT || 3338;
    // ...
    server.listen(port, () => {
      console.log(`Listening on http://localhost:${port}/`);
    });
    

    请参阅:

    如果您希望使用Deploy to Heroku按钮更轻松地部署,那么您可能还需要一个app.json文件:

    但是对于手动部署,您只需要在start中使用package.json脚本,以便您可以使用npm start启动应用,并且您的应用需要从端口收听PORT环境变量。

    您可以使用本地运行来测试它:

    PORT=2255 npm start
    

    并确保您可以在http://localhost:2255/上访问此应用以及您指定的任何其他端口。如果您无法使用上述命令启动应用程序,则您的应用程序不太可能在Heroku上运行。您也可以有一个Procfile预先发布但如果没有它,您至少应该npm start工作,请参阅:

答案 1 :(得分:0)

您似乎正在尝试将 Meteor 应用程序部署到Heroku。

Heroku不像Galaxy那样与Meteor集成,或者像以前的Modulus / Xervo那样集成。

Heroku将检测类似节点的应用,但您需要先将转换您的Meteor应用转换为 Node.js应用,通常使用meteor build命令并上传生成的服务器包,或者使用一些MUP。

一个简单的替代方法是使用第三方Buildpack,一旦您将Meteor应用程序上传到Heroku,它将为您进行转换。

您可以在上面的链接或SO上找到足够的资源。

例如参见:Heroku errors with Meteor 1.4.1.1

注意:NPM_CONFIG_LOGLEVEL=error行是设置,而非实际错误...

答案 2 :(得分:0)

您的Procfile是什么样的?确保您在Procfile中没有web:node app.js。我有同样的错误,并且不需要使用Procfile。一旦我删除它就开始工作了。

答案 3 :(得分:0)

对我来说,事实证明我需要的包不在我的package.json(依赖项)中,当我添加它时,该应用程序开始工作。