Node Express port_url

Node Express port_url

  • npm 鏡像
registry=https://registry.npm.taobao.org

# 這里沒(méi)有從官方 npm 安裝,而是使用了大淘寶的 npm 鏡像
$ npm install express --registry=https://registry.npm.taobao.org
npm list

  • express instance

    var express = require("express");
    
    // 調(diào)用 express instance
    var app = express();
    
    // app 本身有很多方法,其中包括最常用的 get、post、put/patch、delete
    app.get('/', function(req, res) {
      res.send('Hello Word');
    });
    
    app.listen(3000, function() {
      console.log('app is listening at port 3000')
    });
    

    PORT

端口的作用:通過(guò)端口來(lái)區(qū)分出同一臺(tái)電腦內(nèi)不同的應(yīng)用或進(jìn)程,從而實(shí)現(xiàn)一條物理網(wǎng)線,同時(shí)鏈接多個(gè)程序.

端口號(hào),是一個(gè)16位的 unit,所以其范圍為 1 to 65535(對(duì)于 TCP,port 0 被保留,不能被使用. 對(duì)于 UDP,源端的端口號(hào)是可選的,為 0 時(shí),表示無(wú)端口.).

URL

RFC1738 定義的url格式籠統(tǒng)版本是<scheme>:<scheme-specific-part>,scheme有熟悉的http、https、ftp,以及著名的ed2k、thunder.

通常熟悉的url定義成這個(gè)樣子的:

<scheme>://<user>:<password>@<host>:<port>/<url-path>

URI_scheme中提到: URI schemes are frequently and incorrectly referred to as "protocols", or specifically as URI protocols or URL protocols, since most were originally designed to be used with a particular protocol, and often have the same name,尤其是今天移動(dòng)設(shè)備的時(shí)代里, android和ios的開發(fā)中大量使用uri作為跨app通訊通道,把scheme理解為協(xié)議略狹隘了。

  • http.createServer & express.use

    var http = require('http');
    
    http.createServer(function (req, res) {
            res.writeHead(200, {'Content-Type': 'text/html'});
            res.write('<head><meta charset="utf-8" /></head>');
            res.end("你好 \n");
    }).listen(1337, '127.0.0.1');
    
    console.log('Server runnig at http://127.0.0.1:1337/');
    
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容