Node简介

导语:Node.js是一个很不错的后端服务器编程语言,下面介绍Node的概念以及使用方法。

# 目录

  • 简介
  • 作者
  • 适用场景
  • Global
  • REPL环境
  • 运行Node

# 简介

【官网】 (opens new window)

【中文官网】 (opens new window)

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

运行Node.js的代码

node <文件名>
1

# 最后总结

node是非常优秀的使用js编写的后端编程语言。

分享至:

  • qq
  • qq空间
  • 微博
  • 豆瓣
  • 贴吧