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/');