简体   繁体   English

节点-使用git将应用程序部署到heroku

[英]node - deploying app to heroku with git

在此处输入图片说明 在此处输入图片说明 I am trying to deploy my app to heroku and I keep getting this error message saying that it "failed to detect app matching ......." and the push was rejected. 我正在尝试将我的应用程序部署到heroku,并且不断收到此错误消息,提示它“无法检测到应用程序匹配.......”,并且推送被拒绝。 I followed the way it said on the heroku website and I keep getting stuck on only that git push heroku master part I have tried doing some research I couldn't find a solution. 我遵循了heroku网站上的说法,但我一直坚持只使用git push heroku master部分,我尝试做一些研究,但找不到解决方案。 在此处输入图片说明

{
  "name": "home-automation",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server/server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.15.3",
    "johnny-five": "^0.11.3",
    "socket.io": "^2.0.3"
  }
}

Server.js Server.js

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var express = require("express");

var five = require("johnny-five");
var board = new five.Board({port:"COM4"});
const port = process.env.PORT || 3000;

app.use(express.static("public"))

io.on('connection', function (socket) {
    console.log("New User Connected")
    board.on("ready", function(){
        socket.on("turnLightOn", function(data){
            var led = new five.Led({
                pin:"13"
            });
            if(data.status){
                led.on();
            }else{
                led.off();
            }
        })
    })
});

server.listen(port, function(){
    console.log("Listening on port 3000")
});

index.js index.js

var socket = io();

$("#toggle-light").on("click", function(){
    $("#led").toggle();
    if($("#led").css("display") == "none"){
        var status = false
    }else{
        var status = true
    }
    socket.emit("turnLightOn", {
        status
    })
})

index.html index.html

<html>
    <head>
        <title>Home Automation</title>
    </head>
    <body>
        <h1>Home Automation</h1>
        <button id="toggle-light">Toggle Light</button>
        <div id="led" style="width:100px; height:100px; background:yellow;"></div>

        <p id="moistureLevel"></p>
        <script src="/socket.io/socket.io.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="/js/index.js"></script>
    </body>
</html>

This means that a package.json file isn't checked into the root of your git project, so Heroku is detecting that it isn't a Node.js app. 这意味着未将package.json文件检入git项目的根目录中,因此Heroku正在检测到它不是Node.js应用程序。 You can see this locally: 您可以在本地看到此内容:

git show master:package.json

To fix it, you'll want to be sure there is a package.json in the root of your project (where there is also a .git directory), and add it to git: 要修复它,您需要确保在项目的根目录(还有一个.git目录)中有一个package.json,并将其添加到git中:

git add package.json
git commit -m 'track package.json'

The phrasing ('failed to detect set buildpack') could be improved. 措辞(“无法检测到设置的构建包”)可以得到改善。 It should probably say 'failed to detect Node.js app'. 它可能应该说“未能检测到Node.js应用程序”。 When the buildpack's "detect" script is run ( https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/detect ), it looks for a package.json file to verify that there's a node app available to build. 运行buildpack的“检测”脚本( https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/detect )时,它将查找package.json文件以验证是否存在节点应用程序可以建造。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM