0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.jsめも

Posted at

macにnodebrewを導入してjsを実行する

homebrewが入っていない場合はインストールする。
以下は基本的に入っていないことを前提に記述

  • nodebrewを入れる
$ brew install nodebrew
  • node.jsの最新版をインストール
nodebrew install-binary latest

バージョンを指定するときはlatestの部分にバージョンを指定する
(バージョン確認はnodebrew ls-remote

$ nodebrew install-binary latest
Fetching: https://nodejs.org/dist/v8.6.0/node-v8.6.0-darwin-x64.tar.gz
Warning: Failed to create the file
Warning: /Users/hoge/.nodebrew/src/v8.6.0/node-v8.6.0-darwin-x64.tar.gz: No
Warning: such file or directory
                                                                           0.0%
curl: (23) Failed writing body (0 != 941)
download failed: https://nodejs.org/dist/v8.6.0/node-v8.6.0-darwin-x64.tar.gz

とかなってインストールがうまくいかなかったときは
$ mkdir -p ~/.nodebrew/src
でディレクトリ作ってからやるとできるとおもいます

  • 使用するバージョンを指定する

これやらないとcurrentってディレクトリができてなくてパス通すとき困った

$ nodebrew list  ← インストールされているバージョン確認
vX.X.X

current:...

$ nodebrew use vX.X.X

パス通す

$ echo 'export PATH=$PATH:$HOME/.nodebrew/current/bin' >> ~/.bash_profile
$ source ~/.bash_profile

これでnodeが使えるようになってると思うのであとはOO.jsファイルを作って動作させてみる
導入は雑で申し訳ないけど他のサイト見ていただければもっとちゃんと分かると思います‥

実行テスト

test.js
class dog {
    constructor(name){
        this.Name = name
    }
    setName(name){
        this.Name = name
    }
    show(){
        console.log("吾輩は「" + this.Name + "」である"); 
    }
}

function main() {
    let d = new dog("たま");
    d.show();
    d.setName("ねこ");
    d.show()
}

main()
  • 結果
$ node test.js
吾輩は「たま」である
吾輩は「ねこ」である

メンバ変数って定義できないのね

参考URL

0
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?