[英]Deploying Node.js app to Heroku. Error NPM_CONFIG_LOGLEVEL=error
I am deploying my node.js application on heroku but when i run my app it shows me Application error and when i check my logs file i found NPM_CONFIG_LOGLEVEL=error我正在 heroku 上部署我的 node.js 应用程序,但是当我运行我的应用程序时,它显示我应用程序错误,当我检查我的日志文件时,我发现 NPM_CONFIG_LOGLEVEL=error
My package.json file is:我的 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"
}
}
My logs file is:我的日志文件是:
-----> 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
App url is https://whispering-cliffs-66861.herokuapp.com/应用程序网址是https://whispering-cliffs-66861.herokuapp.com/
From your logs:从你的日志:
This app may not specify any way to start a node process
此应用程序可能未指定任何方式来启动节点进程
You probably need to do two things:你可能需要做两件事:
start
script in package.json
package.json
添加start
脚本process.env.PORT
process.env.PORT
的端口Take a look at this example:看看这个例子:
See package.json and the start
script:查看 package.json 和
start
脚本:
"scripts": {
"start": "node server.js"
},
See:看:
And see the port number initialization:并查看端口号初始化:
const port = process.env.PORT || 3338;
// ...
server.listen(port, () => {
console.log(`Listening on http://localhost:${port}/`);
});
See:看:
If you want easier deploy with Deploy to Heroku button then you may also need an app.json
file:如果您希望使用 Deploy to Heroku 按钮更轻松地进行部署,那么您可能还需要一个
app.json
文件:
But for manual deploys you should only need a start
script in package.json
so that you app could be started with npm start
and your app needs to take the port to listen to from the PORT
environment variable.但是对于手动部署,您应该只需要
package.json
的start
脚本,以便您的应用程序可以使用npm start
并且您的应用程序需要获取端口以从PORT
环境变量中侦听。
You can test it with locally running:您可以使用本地运行来测试它:
PORT=2255 npm start
and making sure that you can access your app on http://localhost:2255/ for this and any other port you specify.并确保您可以在http://localhost:2255/上访问您的应用程序,用于此端口和您指定的任何其他端口。 If you cannot start your app with the above command then your app is unlikely to run on Heroku.
如果您无法使用上述命令启动您的应用程序,那么您的应用程序不太可能在 Heroku 上运行。 You could also have a Procfile presend but without it you should at least have
npm start
working, see:你也可以有一个 Procfile presend 但没有它你至少应该让
npm start
工作,请参阅:
You seem to be trying to deploy a Meteor app to Heroku.您似乎正在尝试将Meteor应用程序部署到 Heroku。
Heroku is not as integrated with Meteor as Galaxy is, or as Modulus / Xervo used to be. Heroku 不像 Galaxy 那样与 Meteor 集成,也不像过去的 Modulus / Xervo 那样集成。
Heroku will detect a node-like app, but you will need first to convert your Meteor app into a Node.js app , typically using meteor build
command and uploading the resulting server bundle, or using some MUP thing. Heroku 将检测一个类似节点的应用程序,但您首先需要将您的 Meteor 应用程序转换为Node.js 应用程序,通常使用
meteor build
命令并上传生成的服务器包,或使用一些 MUP 的东西。
A simple alternative is to use a 3rd party Buildpack , which will do the conversion for you once you upload your Meteor app to Heroku.一个简单的替代方法是使用第 3 方Buildpack ,一旦您将 Meteor 应用程序上传到 Heroku,它就会为您进行转换。
You will find plenty resources for that on the above link or here on SO.您可以在上面的链接或 SO 上找到大量相关资源。
See for example: Heroku errors with Meteor 1.4.1.1参见示例: Meteor 1.4.1.1 的 Heroku 错误
Note: the NPM_CONFIG_LOGLEVEL=error
line is a setting , not an actual error…注意:
NPM_CONFIG_LOGLEVEL=error
行是一个设置,而不是实际的错误……
What does your Procfile look like?你的 Procfile 是什么样的? Make sure you don't have web: node app.js in the Procfile.
确保 Procfile 中没有 web: node app.js。 I had the same error and didn't need to use the Procfile.
我有同样的错误,不需要使用 Procfile。 Once I removed it started working.
一旦我删除它开始工作。
对我来说,事实证明我需要一个不在我的 package.json(依赖项)中的包,当我添加它时,应用程序开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.