node.js简介

简介

官网
中文官网

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.

Node.js是构建在 chorme的V8引擎上的一个js运行时

Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient.

事件驱动(回调函数)
非阻塞异步I/O
单线程单进程

Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

作者

Ryan Dahl

适用场景

  • 高并发(双11)
  • 站内信
  • 实时聊天
  • 缺点:不适合大量的计算

Global

在游览器中全局对象(顶层对象)是window
在node中全局对象叫Global

  • Buffer
  • process
  • console
  • setTimeout
  • setInterval
  • clearTimeout
  • clearInterval

REPL环境

进入的方法,在cmd中输入node,然后enter,就可以进入node的REPL环境。

  • Read 读,读取用户输入,解析输入的JS数据结构并存储在内存中
  • Eval 执行,执行输入的数据结构
  • Print 打印,输出结果
  • Loop 循环 ,循环操作以上步骤,直到CTRL+C以后
  • 退出REPL环境,用Ctrl+C两次

运行Node.js的代码

$ node <文件名>

原文地址:https://www.cnblogs.com/guanqiweb/p/9853279.html