0
0

More than 5 years have passed since last update.

nodejsのサンプルページをherokuで公開する

Last updated at Posted at 2019-02-28

・模索しながら書くぞ
・環境はubuntu、バージョンはわからないが多分最新
・言葉の使い方がわかっていない
・Glitchというサイトが使いやすかったが、socket.ioが使えないためherokuでやることに。ここに備忘としてメモ。

参考にしたページ、無断リンクだけど
https://developer.salesforce.com/events/webinars/nodejs_heroku_0525/
http://tacamy.hatenablog.com/entry/2013/02/16/235127
https://devcenter.heroku.com/articles/heroku-cli
https://qiita.com/chihiro/items/5c3ff400f6cb99deb945
https://qiita.com/yoh-nak/items/80e51197410c7f956ccd
https://qiita.com/sayama0402/items/e2c9e65786259dc55e11

やったこと

1, herokuに登録

2, gitに登録(githubに登録すればgitに登録したことになるの?過去に色々やってわからなくなってしまった)

3, gitをインストール

$sudo apt-get install git-all

4, herokuのtoolbeltをインストール
(わからなければ、https://devcenter.heroku.com/articles/heroku-cli にアクセスするとなんかうまく行く)
つまり、このページの言うとおりに、

$ sudo snap install --classic heroku

を実行

(もしいろいろやって入ってるかどうか分からなくなっちゃったら

$ heroku -v

でOK)

5, それから下記を実行、ブラウザに飛ばされてログインする

$ heroku login

6, プロジェクトを作る
プロジェクトがあるディレクトリにcdで移動してから、

$ heroku create [任意の名前]

でプロジェクトができる。$ heroku apps とかherokuホームページのマイページみたいなところでプロジェクトの一覧を確認できる

ここから手探り、すでにあるアプリのディレクトリ内で作業しているがそれが正しいのか?
それから

7, git リポジトリを初期化

$ git init

$ git status

8, それからProcfileを作成

Procfile
web: node bin/www

9, それからgitの操作

$ git add Procfile *.js *.json public views routes bin
  //これが先にできた

$ git config --global user.email "[任意のメアド]"
 //ログインをここでした

$ git commit -m "[任意のコメント]"
  //コミットをした

最後のをすると、コマンドにこんなのが出る

[master (root-commit) ea77c2d] 2/28にコミット
 10 files changed,  180 insertions(+)
 create mode 100644 Procfile
 create mode 100644 app.js
 create mode 100755 bin/www
 create mode 100644 package.json
 create mode 100644 public/stylesheets/style.css
 create mode 100644 routes/index.js
 create mode 100644 routes/users.js
 create mode 100644 views/error.jade
 create mode 100644 views/index.jade
 create mode 100644 views/layout.jade

多分うまく行っている

10, それから、「.gitignore」という名前のファイルを作り、中に

.gitignore
node_modules

とだけ書く。.から始まるファイルは隠しファイルなので、デフォルトでは表示されていない。

11, gitにリモートリポジトリを作成

$ git remote add heroku git@heroku.com:[プロジェクトの名前].git

※[プロジェクトの名前]のところには、heroku create []でいれたやつを入れる

実行しても何も応答がないのでやや怖い

(以下でリモートリポジトリ削除

git remote remove heroku

(以下のように出たら
```
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
```
、11をすれば良い)

.git/configもうまく行っているっぽいのを確認し、気を取り直して、

12, gitにpush

$ git push heroku master

を実行

13, それから

$ heroku start

を実行。startではなくrestartだと怒られたが知らんしどっちでもいい

・そしてheroku createのときに返されたurl(herokuapp.comで終わるやつ)にアクセスすると

・うまくいった!!

・更新する

・以下の3つを実行

$ git add .

$ git commit -m "message"

$ git push heroku master

うまくいかない
sshkeyが無いせいかと思い
https://qiita.com/SomeyaNaoki/items/fbd359b20c1b479692f9
に則って操作

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0