我创建了我的第一个node.js服务器应用程序,并且我在Heroku上部署了错误。在日志中它告诉我应用程序已成功启动,但我有#34; App Error"在heroku网址
已经检查了我的package.json并没有发现任何麻烦。
我做错了什么?
server.js:
'use strict';
const http = require('http');
const fs = require('fs');
const server = http.createServer(function (request, response) {
console.log(request.method, request.url);
if (request.url == '/style.css'){
const css = fs.readFileSync('style.css', 'utf8');
response.end(css);
}else{
const html = fs.readFileSync('index.html', 'utf8');
response.end(html);
}
});
console.log('port = ', process.env.PORT);
server.listen(process.env.PORT || 3000);
console.log('Server Started, yay!');
的package.json:
{
"name": "Enigma",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}
和Heroku日志:
-----> 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): unspecified
engines.npm (package.json): unspecified (use default)
Resolving node version 6.x...
Downloading and installing node 6.11.4...
Using default npm version: 3.10.10
-----> 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!
-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> web
-----> Compressing...
Done: 15M
-----> Launching...
Released v11
https://enigma-test.herokuapp.com/ deployed to Heroku
答案 0 :(得分:1)
我们需要告诉Heroku如何运行我们的应用程序。只需使用以下内容创建一个名为Procfile的新文件:
web: node server.js
然后尝试再次部署代码&然后重启heroku
heroku restart --app application_name
答案 1 :(得分:1)
可能你错过了Procfile
,其中包含:
web: node .
我在enigma-test-2上成功部署了您的应用程序(我现在已经从我的帐户中删除了该应用程序)
您可以找到我在此部署的项目的完整副本,该副本完全使用您的代码:Repo
一旦克隆了要点:
git clone https://gist.github.com/MatteoRagni/2be84fbece541e2f3f324b3cd8fd4b00 enigma-test
您可能想要部署它:
heroku login
# make your login
cd enigma-test
heroku git:remote -a enigma-test-2
# make your modifications
git commit -am "commit for heroku"
git push heroku master
您现在应该在heroku上看到您的应用程序。