2013年4月10日 星期三

簡單的NodeJS Http Server實作


Noder - Simple HTTP Server

Noder是透過NodeJS的HTTP模組製作的簡單HTTP Server,讓使用者可以透過簡單的指令來啟動HTTP服務來提供本地端檔案的檔案瀏覽,支援npm安裝∼

Picture: Easy to use of noder!

安裝

透過npm指令安裝,因為這個安裝需要安裝指令,因此安裝時要指定"-g"來安裝到global
    # sudo npm install noder -g  
PS: 是不是要使用sudo...就看您電腦的使用者是不是有權限拉

使用

預設啟動會listen 1337 port,並且服務會啟動在127.0.0.1...
# noder --help

  Usage: noder [options]

  Options:

    -h, --help                     output usage information
    -V, --version                  output the version number
    -h, --host [ip]                Specific host, like 192.168.1.1, default is all ip listened
    -p, --port <port>              Specific port, like 80,3000,8080, default is 1337
    -a, --allow <allow file type>  Specific the allowed file types that seprate by ",", default is all
    -d, --deny <deny file type>    Specific the denied file types that seprate by ",", default is none

瀏覽

服務啟動後,您可以打開瀏覽器瀏覽: http://127.0.0.1:1337/test.html