Node Express port_url
- npm 鏡像
registry=https://registry.npm.taobao.org
# 這里沒有從官方 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
端口的作用:通過端口來區(qū)分出同一臺電腦內(nèi)不同的應用或進程宰掉,從而實現(xiàn)一條物理網(wǎng)線赁濒,同時鏈接多個程序.
端口號拒炎,是一個16位的 unit挨务,所以其范圍為 1 to 65535(對于 TCP,port 0 被保留丁侄,不能被使用. 對于 UDP朝巫,源端的端口號是可選的,為 0 時捍歪,表示無端口.).
URL
RFC1738 定義的url格式籠統(tǒng)版本是<scheme>:<scheme-specific-part>
户辱,scheme有熟悉的http
、https
糙臼、ftp
,以及著名的ed2k
恩商、thunder
.
通常熟悉的url定義成這個樣子的:
<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
变逃,尤其是今天移動設備的時代里, 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/');