CLI 로 실행하는 서버
서버를 구동하는 방법은 IOSignal 라이브러리를 사용하여 직접 코딩을 하는방법 외에도 CLI프로그램을 사용 방식도 있습니다.
사전준비
우선 node.js 가 설치되어 합니다. 윈도우, 맥, 리눅스 모두 설치 가능합니다.
iosignal-cli 프로그램 설치
맥이나 리눅스에서는 아래와 같은 명령어로 설치합니다.
- 전역 설치가 필요하므로 sudo 관리자권한으로 설치해야합니다.
- -g 옵션을 추가하여 전역 설치하도록 합니다.
$ sudo npm i -g iosignal-cli
윈도우즈
- 전역설치를 위해 -g 옵션을 추가합니다.
- 설치 시 권한오류가 뜰 경우 터미널이나 명령창을 관리자모드로 실행 후 다시 시도해보시기 바랍니다.
npm i -g iosignal-cli
서버 실행 명령어 io-server 또는 ios
cli 프로그램이 정상 설치된 경우, 새로운 터미널이나 명령창을 열고 아래 명령문을 입력해봅니다.
- 서버 실행시 옵션 도움말을 보여주는 명령입니다.
- io-server 가 서버실행 명령입니다. 단축 키워드로 ios 를 사용할 수도 있습니다.
% ios -h
Usage: ios [options] (--listen <port> )
Options:
-V, --version output the version number
-l, --listen <port> listen on port (start WebSocket Server)
-L, --listen-congport <port> listen on cong port (start CongSocket Server)
-d, --auth-file <path> auth data file path
-e, --auth-param <id.key.level> auth data from argument:
id.key.level,id2.key2.level2
-E, --auth-env auth data from shell env BOHO_AUTH
-r, --auth-redis connect to redis. if exist use env REDIS_HOST,
REDIS_PORT or localhost:6379
-t, --timeout <milliseconds> ping period & timeout
-m, --metric <type> show metric <number> 1:traffic, 2:echo
-s, --show-message <none|message> show receive message.
-f, --file-logger write log files.
-a, --api-list [list...] one or multiple api names: -a api_1 api_2
-o, --show-options show server init options.
-h, --help display help for command