Practical Node.js chapter 1

啓動node.js腳本

$ NODE_ENV=production API_KEY=442CC1FE-4333-46CE-80EE-6705A1896832 node server.jsnode

Node.js 控制檯 REPL

在終端敲node進入replchrome

1+1
a = 1;npm

基礎知識

Node.js是創建在Google Chrome V8引擎和ECMASCRIPT之上的。瀏覽器

命名

靜態變量或者私有函數以_開頭curl

保留的關鍵詞

  1. process
  2. global
  3. module.exports

__dirname和process.cwd
絕對路徑
若是像這樣啓動
$ node ./code/program.js.

二者的路徑是不同的函數

核心模塊

  1. htpp
  2. util
  3. querystring
  4. url
  5. fs
  6. path
  7. crypto
  8. string_decoder

調試node.js程序

  1. Node.js Debugger 並很差用
  2. Node Inspector Chrome devtools的一個端口
  3. Webstrom IDE調試 很是好用
  4. console.log

使用Node.js Debugger

node debug hello.jsurl

next 快捷鍵n 跳到下一個語句
cont 快捷鍵c 跳到下一個斷點
step s 進入function
out o 跳出function
watchdebug

打開瀏覽器 http://localhost:1337調試

或者執行 curl http://localhost:1337code

使用Node Inspector

npm install -g node-inspector

而後,啓動node-inspector
node-inspector

在新的終端打開
node —debug-brk hello-debug.js or node —debug hello-debug.js

打開chrome瀏覽器 其它瀏覽器不能夠
http://localhost:8080/debug?port=5858

檢測文件改動

  1. forever
  2. nodemon
  3. supervisor
  4. up
相關文章
相關標籤/搜索