将Node.js应用程序部署到Heroku。 错误NPM_CONFIG_LOGLEVEL =错误
我在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
应用url是https://whispering-cliffs-66861.herokuapp.com/
从你的日志:
此应用程序可能不指定任何方式来启动节点进程
你可能需要做两件事情:
- 在
package.json
添加start
脚本 - 确保你在
process.env.PORT
监听端口
看看这个例子:
请参阅package.json和start
脚本:
"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
如果你想更容易部署与部署到Herokubutton,那么你可能还需要一个app.json
文件:
但是对于手动部署,您只需要在package.json
使用start
脚本,以便可以使用npm start
应用程序,并且您的应用程序需要从PORT
环境variables中获取PORT
。
你可以用本地运行来testing它:
PORT=2255 npm start
并确保您可以访问您的应用程序在http:// localhost:2255 /为此和您指定的任何其他端口。 如果你不能用上面的命令启动你的应用程序,那么你的应用程序不太可能在Heroku上运行。 你也可以有一个Procfile预先发送,但没有它你应该至less有npm start
工作,请参阅:
你似乎正试图部署一个Meteor应用程序到Heroku。
Heroku不像Galaxy一样和meteor结合,或者像Modulus / Xervo一样。
Heroku会检测类似节点的应用程序,但是您首先需要将您的Meteor应用程序转换为Node.js应用程序 ,通常使用meteor build
命令并上传生成的服务器包,或者使用一些MUP的东西。
一个简单的select是使用第三方的Buildpack ,一旦你将Meteor应用上传到Heroku,它将为你做转换。
你会发现在上面的链接或在这里的很多资源。
看例如: meteor1.4.1.1的Heroku错误
注意: NPM_CONFIG_LOGLEVEL=error
行是一个设置 ,而不是实际的错误…
你的Procfile是什么样的? 确保在Procfile中没有web:node app.js。 我有相同的错误,并不需要使用Procfile。 一旦我删除它开始工作。