export default 導出 import 導入 (ES6 module)javascript
cnpm install <包名> -g 全局安裝css
cnpm install <包名> --save-dev 局部安裝 cnpm i <包名> -Shtml
cnpm uninstall <包名> 卸載java
cnpm update <包名> 更新node
cnpm clear cache 清除緩存jquery
cnpm install jquery qs url -S(加載jquery qs url爲同步:按順序執行)chrome
yarn install === cnpm install package.json依賴安裝數據庫
yarn add <包名> === cnpm install <包名> -S 局部安裝npm
yarn add <包名> --dev == cnpm install <包名> --save-dev 局部安裝json
yarn upgrade <包名> 更新
yarn remove <包名> 刪除
//引入http模塊 node的核心模塊 const http = require("http"); /* //商場 const server = http.createServer() 建立服務器 //端口號 server.listen(9000) 用戶說:"商店裏面有沒有澡巾" url:"http://ww.baidu.com/data" 人民幣 get post 要綠色 多大號的 headers:{ "content-type":"application/json"{name:val,pass:val} "application/x-www-form-urlencoded" 表單序列化 name=val&pass=val "{'name':'zhangsan','age':19}" } 回覆 res.end() + res.write 最後的回覆 res.write(); 響應 content-tyepe */
http.createServer((req,res)=>{ console.log(req.headers) /* req:request req.url 請求的地址 req.method 請求的方式 req.headers 請求頭 req.body 接收post傳遞的參數 req.query 接收get傳遞過來的參數 req.request() 接收任意方式傳遞過來的數據 res:response res.write() 回覆響應信息 能夠調用不少次 res.end() 回覆響應信息 作結尾 只能調用一次 res.statusCode 設置狀態碼 res.setheader() 設置響應頭 res.writeHead(); statusCode 與setHeader的綜合寫法 第一次參數是狀態碼 第二次參數是響應頭的類型 */ //res.statusCode = 200; //res.setHeader("content-type","text/plain"); res.writeHead(200,{"content-type":"text/plain;charset=utf8"}); res.write("1111"); res.write("2222"); res.end("你好"); }).listen(9000) //提示信息 console.log("http://localhost:9000") /* 響應頭的類型有哪些? text/plain 文本類型 text/html html類型 text/css css類型 application/x-javascript js類型 application/json json類型 application/xml xml類型 image/png jpg gif */
小案例:
moduleA.js
const moduleA = require("./moduleB"); const cheerio = require("cheerio"); console.log(moduleA._name); console.log(moduleA.fn("哈哈"))
moduleB.js
let _name = "張三"; let fn = (name)=>{ console.log(name); } module.exports = { _name, fn }