将Node.js应用程序部署到Heroku.错误NPM_CONFIG_LOGLEVEL =错误
我在heroku上部署了node.js应用程序,但是当我运行我的应用程序时,它向我显示应用程序错误,并且当我检查日志文件时发现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
我的package.json文件是:
My package.json file is:
{
"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
从您的日志中
此应用可能未指定任何启动节点进程的方式
This app may not specify any way to start a node process
您可能需要做两件事:
- 在
package.json
中添加 - 确保您在
process.env.PORT
中的端口上进行监听
start
脚本
- add
start
script inpackage.json
- make sure you listen on the port in
process.env.PORT
看看这个例子:
请参阅package.json和start
脚本:
See package.json and the start
script:
"scripts": {
"start": "node server.js"
},
请参阅:
并查看端口号初始化:
const port = process.env.PORT || 3338;
// ...
server.listen(port, () => {
console.log(`Listening on http://localhost:${port}/`);
});
请参阅:
- https://github.com/rsp /node-live-color/blob/master/server.js#L13
- https://github.com /rsp/node-live-color/blob/master/server.js#L46-L48
- https://github.com/rsp/node-live-color/blob/master/server.js#L13
- https://github.com/rsp/node-live-color/blob/master/server.js#L46-L48
如果要使用部署到Heroku"按钮更轻松地进行部署,则可能还需要一个app.json
文件:
If you want easier deploy with Deploy to Heroku button then you may also need an app.json
file:
但是对于手动部署,您只需要在package.json
中使用start
脚本,以便您可以使用npm start
启动应用程序,并且您的应用程序需要使用端口来监听PORT
环境变量.
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.
您可以在本地运行的情况下对其进行测试:
You can test it with locally running:
PORT=2255 npm start
,并确保您可以在 http://localhost:2255/*问您的应用您指定的其他端口.如果您无法使用上述命令启动应用程序,则您的应用程序不太可能在Heroku上运行.您也可以预先安装一个Procfile,但是没有它,您至少应该让npm start
工作,请参见:
and making sure that you can access your app on http://localhost:2255/ for this and any other port you specify. If you cannot start your app with the above command then your app is unlikely to run on Heroku. You could also have a Procfile presend but without it you should at least have npm start
working, see:
- https://devcenter.heroku.com/articles/procfile
- https://devcenter.heroku.com/articles/nodejs-support