再度HerokuでHelloWorld
はじめてのHeroku(node.js) - 四角革命前夜で作ってbitbucketに上げたものを、GitHubに作り直して再度上げ直したりしただけ……なのですけど。
あとコマンドの練習とか。
環境:MacOS 10.6.8 / nodebrew 0.5.0 / node.js 0.6.17 / npm 1.1.9
GitHubにリポジトリを作る
GitHubにリポジトリを作って、それをクローンしてきます。
$ git clone git@github.com:sasaplus1/heroku-helloworld.git
GitHubでリポジトリ作るのに慣れていないのでなんだか……こう……
そのうちbitbucketみたく慣れるといいなあ。
HelloWorldに必要なものを書く
{ "name": "heroku-helloworld", "version": "0.0.1", "dependencies": { "express": "2.5.9" }, "engines": { "node": "0.6.17", "npm": "1.1.9" } }
buildpackは本家Herokuのものを使うので、
http://heroku-buildpack-nodejs.s3.amazonaws.com/manifest.nodejs
http://heroku-buildpack-nodejs.s3.amazonaws.com/manifest.npm
にあったそれぞれ最新のものを記述しました。
書いたらexpressをインストールします。
$ npm install
次にスクリプトを書きます。ファイル名はapp.jsで。
var express = require('express'), app = express.createServer(); app.get('/', function (req, res) { res.send('Hello, World!'); }); app.listen(process.env.PORT || 3000);
どこにアクセスしてもHello, Worldが返ってきます。
あとはProcfileの生成と、.gitignoreを生成します。
$ echo 'web: node app.js' > Procfile $ echo 'node_modules/' > .gitignore
最後にコミットとプッシュを。
$ git add . $ git st # git statusのエイリアス $ git ci -m "initial commit" # git commit -a -vのエイリアス $ git push origin master
今あるアプリを作り直す
再度作り直すので、動作しているアプリを削除します。
$ heroku apps:destroy --app heroku-helloworld
確かもう一度アプリ名を入力するように聞かれたはず……
$ heroku apps:create --stack cedar --buildpack http://github.com/heroku/heroku-buildpack-nodejs.git
リネームはよくわからなかったのでウェブから。情けない……
$ heroku apps:rename heroku-helloworld --app [作成されたアプリ名]
でいいのかなあ?
で、プッシュしようと思ったら
$ git push heroku master
でアプリ名を変更しているのでプッシュできず。
$ git remote rm heroku
$ git remote add heroku git@heroku.com:heroku-helloworld.git
$ git push heroku master
で無事プッシュできて、ちゃんと動くように!
アプリとリポジトリです。
……そろそろHelloWorldだけじゃなくてまともに動くもの作りたい。