2018年3月27日火曜日

VRゲームを作る6 - ローカルホストサーバの立ち上げ

前回のリベンジ。
結果としてはローカルサーバの立ち上げに成功した。

詳細は以下。

やり方はExpressの公式サイトにあった手順に従っただけ。
今までの苦労はなんだったんだ。

先ずはデスクトップとかに適当にディレクトリ(フォルダ)作成し、
コマンドプロンプトでそこに持ってくる。
ディレクトリの移動
1
C:C:\Users\(username)> cd C:\Users\(username)\Desktop\test

そしたらpackage.jsonを作成。
package.jsonの作成
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
C:\Users\(username)\Desktop\test>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
 
See `npm help json` for definitive documentation on these fields
and exactly what they do.
 
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
 
Press ^C at any time to quit.
package name: (test)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to C:\Users\(username)\Desktop\test\package.json:
 
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}
 
 
Is this ok? (yes)
 
 
   ╭─────────────────────────────────────╮
   │                                     │
   │   Update available 5.6.0 → 5.8.0    │
   │       Run npm i npm to update       │
   │                                     │
   ╰─────────────────────────────────────╯
</pkg>
Press ^C at any time to quit.の辺りで止まるから、
Enter連打で最後まで飛ばす。

で、socket.ioのインストールを実施。
socket.ioのインストール
1
2
3
4
5
6
7
8
9
10
11
12
C:\Users\(username)\Desktop\test>npm install socket.io
 
> uws@9.14.0 install C:\Users\(username)\Desktop\test\node_modules\uws
> node-gyp rebuild > build_log.txt 2>&1 || exit 0
 
npm notice created a lockfile as package-lock.json. You should commit this file.
 
npm WARN test@1.0.0 No description
npm WARN test@1.0.0 No repository field.
 
+ socket.io@2.0.4
added 43 packages in 8.252s

WARN出てるけど無視してexpressのインストール

expressのインストール
1
2
3
4
5
6
C:\Users\(username)\Desktop\test>npm install express
npm WARN test@1.0.0 No description
npm WARN test@1.0.0 No repository field.
 
+ express@4.16.3
added 41 packages in 5.982s

そしたらapp.jsという名前の空ファイルを作成して、
そこに先頭のURLにあったソースコードを記載して保存。
で、コマンドプロンプトに以下を打ち込む。
サーバの起動
1
2
C:\Users\(username)\Desktop\test>node app.js
Example app listening on port 3000!

これで適当なブラウザからhttp://localhost:3000/にアクセスすればHello Worldが表示される。
終了時はコマンドプロンプトでCtrl+C。

あとはチャット作ろうか、と思ったけど
何故かここで難航しているのでまたの機会に。