1. 程式人生 > >note.js 筆記第一課

note.js 筆記第一課

creates ins 類型 utf req pla 批量 count charset

第一部分:環境安裝
>1.下載安裝nodejs
>01.http://www.nodejs.org/zh-cn/
>02.http://www.nodejs.org/en/
>03.msi版本的用來安裝
>04.tar.gz版本用來配置webstorm
>2.了解npm包管理工具
>01.npm初始化
>001. npm init
>002.文件夾名字不可包含大寫字母
>003.文件夾名字不可有空格
>02.查看安裝包:
>001. npm ls
>002. npm ls -g
>03.下載bower包管理工具
>001. npm install bower -g
>04.特定版本(bower info 包名)查看包的版本信息
>001. npm install [email protected] --save
加--save有兩個作用
0001->將下載的包的信息添加到package.json文件裏
0002->將下載下來包放到當前項目目錄的node_modules

>05.dev結點(只在開發時用到的模塊信息放到dev節點)
>001. npm install body-parser --save-dev
>06.批量拉包
>001.npm install ==》dependencies和devDependencies
>002.npm install --prod ==》dependencies
>003.npm install --only=dev ==>devDependencies
>07.移除包
>001.npm uninstall packageName
>002.npm uninstall packageName -g


(用bower必須要下載git)

-----------------------------------------------------------------------------------------------
第二部分:hello-world
>1.在cmd或者git bash裏運行:node 01.js
>01.如果被占用,則把代理清除
>001.npm config set proxy null
>2.通過npm下載web框架express

-----------------------------------------------------------------------------------------------
第三部分:基本組件1:console
>1.console.log:打印日誌
>2.console.info:打印信息
>3.console.warn:打印警告
>4.console.error:打印錯誤
>5.console.dir:打印信息,類型
>6.console.time(‘tagName‘):開始計時 ****
>7.console.timeEnd(‘tagName‘):結束計時****
>8.console.trace():跟蹤函數執行過程
>9.console.assert(表達式):斷言****
-----------------------------------------------------------------------------------------------
第四部分:HTTP
>1.引入模塊http
>01.require(‘http‘)
>2.創建服務器:createServer
>01.server=http.createServer(function(req,res){});
>01.writeHead:響應頭
>001.res.writeHead=object
>002.200-配置
>01:text/html:以html形式返回
>02:text/json:以json格式返回
>03:text/xml:以xml格式返回
>04:text/plain:原樣返回
>05:charset=utf-8
>06:‘txt‘: ‘text/plain‘,
‘html‘: ‘text/html‘,
‘css‘: ‘text/css‘,
‘xml‘: ‘application/xml‘,
‘json‘: ‘application/json‘,
‘js‘: ‘application/javascript‘,
‘jpg‘: ‘image/jpeg‘,
‘jpeg‘: ‘image/jpeg‘,
‘gif‘: ‘image/gif‘,
‘png‘: ‘image/png‘,
‘svg‘: ‘image/svg+xml‘
>003.301-{‘Location‘:‘新地址‘}
>02.監聽:listen
>01.server.listen(port,hostname,callback);
>02.port:監聽端口
>03.hostname:監聽主機名
>04.callback:回掉函數
>001.function(err){console.log(err);}
-----------------------------------------------------------------------------------------------
第六部分:練習
>1.//創建一個監聽 on/addListener
//打印出監聽的函數數量:ListenerCount
//移除掉監聽函數,removeListener
//執行監聽 emit

note.js 筆記第一課