节点 - 使用git

时间:2017-07-19 00:40:58

标签: node.js git heroku

enter image description here enter image description here我正在尝试将我的应用部署到heroku,并且我一直收到此错误消息,说它"未能检测到应用匹配.......&# 34;推动被拒绝了。我按照它在heroku网站上所说的方式进行了跟踪,并且我一直卡在那个git push heroku master部分我已经尝试做一些我无法找到解决方案的研究。 enter image description here

{
  "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

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

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

<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>

1 个答案:

答案 0 :(得分:1)

这意味着没有将package.json文件签入git项目的根目录,因此Heroku检测到它不是Node.js应用程序。你可以在本地看到这个:

git show master:package.json

要修复它,你需要确保项目的根目录中有一个package.json(还有一个.git目录),并将它添加到git:

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

可以改进措辞('未能检测到set buildpack')。应该说'未能检测到Node.js app'。当运行buildpack的“detect”脚本(https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/detect)时,它会查找package.json文件以验证是否有可用于构建的节点应用程序。