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
相关文章
相关标签/搜索