缺少脚本:在部署nodejs到heroku时启动
Missing script: start when deploying nodejs to heroku
所以我试图将我的nodejs应用程序部署到heroku。
我在package.json
"scripts": {
"test": "./node_modules/.bin/mocha -r mocha-cakes",
"start": "rm -r -f database/test.db && node app.js",
"start-win": "del database''test.db && node app.js"
}
我还将web: rm -r -f database/test.db && node app.js
添加到Procfile
然而,我的dyno仍然崩溃,并出现以下日志错误:
2016-06-25T12:27:58.216435+00:00 heroku[web.1]: Starting process with command `npm start`
2016-06-25T12:28:00.503447+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-06-25T12:28:00.502867+00:00 app[web.1]: npm ERR! Linux 3.13.0-85-generic
2016-06-25T12:28:00.504156+00:00 app[web.1]: npm ERR! npm v3.8.6
2016-06-25T12:28:00.503707+00:00 app[web.1]: npm ERR! node v5.11.1
2016-06-25T12:28:00.506550+00:00 app[web.1]: npm ERR! missing script: start
2016-06-25T12:28:00.506746+00:00 app[web.1]: npm ERR!
2016-06-25T12:28:00.506912+00:00 app[web.1]: npm ERR! <https://github.com/npm/npm/issues>
2016-06-25T12:28:00.516583+00:00 app[web.1]:
2016-06-25T12:28:00.516795+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-06-25T12:28:00.516913+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2016-06-25T12:28:00.506796+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:
2016-06-25T12:28:00.505628+00:00 app[web.1]:
2016-06-25T12:28:01.445657+00:00 heroku[web.1]: Process exited with status 1
2016-06-25T12:28:01.461079+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-25T12:28:01.461867+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-25T12:28:04.433811+00:00 heroku[web.1]: Starting process with command `npm start`
我已经检查了其他SO个问题,没有一个答案能解决我的问题。我已经尝试了其他帖子推荐的所有方法,但还没有发现任何成功。
如果你想看源代码,这里是我的repo的链接。
在创建表后的/database/database.js文件中,如果这些表不存在,则有一个db.run查询读取该XML文件。
db.run('INSERT OR IGNORE INTO managers (username, password) VALUES ("admin","admin")', function(){
//
// Dear fellow coder:
//
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
//
// total_hours_wasted_here = 3
//
// When I wrote this, only God and I understood what I was doing
// Now, God only knows
//
// Magic, Do not touch
//initialise the table values from log file
// I want to read the xml file after the database tables have been created. HACK HACK!!!
$this.readLogFile();
console.log('Loaded Data from XML document');
});
我不确定除了测试你在部署的代码中有这个之外的原因是什么。我猜想您希望在部署后删除DB的原因是您只在测试中需要它。
由于Heroku似乎不喜欢rm -r -f database/test.db
,我建议您将其注释出来以进行部署,或者作为更优雅的解决方案,在调用此DB查询之前添加if语句,该查询仅在您具有布尔值为true的TESTING环境变量时才运行它。您还应该从启动脚本中删除rm -r -f database/test.db
。
您的方法的另一个问题是,开始脚本甚至在导入XML文件之前运行,因此对开始脚本中的db的任何操作都不会删除它。
相反,你也可以创建一个查询,每次启动服务器时在app.js中调用。该查询应该清空整个DB。但是当你可以不读它的时候,为什么要读它并删除它呢?
相关文章:
- 我的jQuery插件参数没有正确启动,遇到了问题
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 从控制器返回后Ajax启动事件激发
- Meteor上的启动页面
- 如何防止网页加载后自动启动功能
- 如何从JavaScriptInterface启动Navigation Drawer
- window.on.scroll事件未启动
- 单击按钮后启动javascript提示
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- spine.js在启动时填充模型实例
- 如何在所有ng点击事件AngularJS上启动一个方法
- jQuery悬停在没有鼠标悬停的情况下启动
- SignalR客户端启动连接时如何设置用户
- Meteor:在启动时将html注入客户端文件
- Angular UI启动日期选择器问题
- 如何用低音量自动启动Youtube视频(iframe)
- jQuery mouseup在拖离链接后未启动
- nodejs和heroku:抛出新错误(setHeader()需要“名称”和“值”');
- 以这种方式在Heroku上启动Node.js应用程序可以吗
- 缺少脚本:在部署nodejs到heroku时启动