Node 技术栈

作者: 1Z实验室阿凯 | 来源:发表于2016-09-30 14:50 被阅读1383次

Note :随着学习的深入,技术框架的具体细节和概念介绍会后续补充。

整体架构

前后端分离 (API架构)任务通知 项目沟通 协作文档传输

前端

jQuery

@Introduction

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.

@Feature

  • 易用 语法简单,API易用
  • 浏览器兼容DOM元素操作等

@Reference

ReactJS

React是一个新东西,它的理念是可重复使用的WEB组件。这个库是由Facebook开发的,因为是虚拟DOM,它的性能非常突出,它还能很容易的集成到其它项目中。
后台

React中文网
http://react-china.org/
React 入门实例教程-廖雪峰
http://www.ruanyifeng.com/blog/2015/03/react.html

2 后台

2.1 NodeJS 6.6.0 - JS运行环境

替代文字替代文字
Introduction

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

Feature

  • 生态和工具链
    模块丰富 npm现在已经时开源世界中最大的包管理工具,模块丰富(300,000+),可以极大方便开发。
    社区活跃 除了Node基金会在其公告中提到的Node.js“超过350万用户和100%的年增长速度”,npmjs公布了一些NPM统计数据:211000NPM注册用户中73000用户至少发布了一个包,每月有超过300万唯一的IPs访问NPM注册表,大约有400万用户,三月份有超过8千万的NPM会话,每星期有超过10亿的包下载量。这些数字显示出JavaScript,Node.js和NPM构建的生态系统正在蓬勃发展。

  • 前后端统一
    前后段都采用JS语法,可以开发量(例如数据验证)

  • 异步
    事件驱动(event-driven)
    非阻塞I/O(non-blocking I/O)
    异步与同步相比,更节省内存消耗,提高并发处理的速度

  • 足够多的选择和架构平衡

  • 为何要用NodeJS 6.6.0 ?
    启动更快 Node6.X 采用V8.5.0内核,模块加载比Node.js 4.x快了近四倍。这意味着应用程序的启动会非常快。
    高级ES特性支持 支持 93% 的ES2015语法。包括解构(destructuring)、剩余参数(rest parameters)、类(class)以及super关键字。不支持的有直接或相互递归、迭代器关闭等其它一些语法。其中一些已经准备好了,但需要harmony flag才能使用。
    安全性
    新的Buffer API使用新的构造器创建Buffer实例,并引入了zero-fill-buffers命令行标志,这样会减少错误的风险并且避免漏洞泄露到应用程序中。使用新的命令行标志,开发人员可以继续安全地使用旧的模块,即使这些模块没有更新,没有使用新的构造器API。另外,V8改进了Math.random()的实现,使之更安全——这个特性也添加到了 Node.js v6。
    易用性
    Buffer 和 File System API 的易用性得到提高
    更全面的测试覆盖率
    更完善的文档

@Reference

2.2 Koajs2 - Node.js Web框架

Koajs2Koajs2
Introduction

Koa is a new web framework designed by the team behind Express, which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs. Through leveraging generators Koa allows you to ditch callbacks and greatly increase error-handling. Koa does not bundle any middleware within core, and provides an elegant suite of methods that make writing servers fast and enjoyable.

Feature

  • 轻量级 [ 更小,更健壮,更有表现力]
    KoaJS是对Nodejs的http模块的进一步抽象,不在内核方法中绑定任何中间件,功能单一。
  • 新特性支持
    Koa2采用的ES2015新的特性(arrow function, promise, let const, template string, class )。
  • 流程控制
    在 1.0 时候 koa 需要依赖 co 结合 generator 实现 stack like 式的 middleware 功能, 2.0 移除了对 co 的依赖, 改而使用 Promise 实现该功能.
    其中的async/await的新特性(来自ES2016)需要babel@6.x配合使用。
    避免繁琐函数回调,提高错误处理效率

@Reference

2.3 Mongoose - MongoDB 的NodeJS驱动(可异步执行)

@Introduction

[1]mongoose elegant mongodb object modeling for node.js
Mongoose provides a straight-forward, schema-based solution to model your application data.

[2]Mongoose is a Node.js library that provides MongoDB object mapping similar to ORM with a familiar interface within Node.js.

Mongoose 是一个提供MongoDB对象映射的Nodjs库.提供在MongoDB存储的数据与Javascript的对象之间的映射。
ODM Object Data Mapping .类似于NodeJS提供的ORM(Object Relational Mapping)接口.

@Feature

[TODO]

  • built-in type casting
  • validation 数据检验
  • query building 查询构建
  • business logic hooks

@Reference

2.4 Nunjucks - 视图模板

@Introduction

@Feature

@Reference

2.5 Bluebird - Promise/A+实现

替代文字替代文字

Bluebird-NodeJs的Promise

Q:何为Promise?
Promise是异步代码实现控制流的一种方式。这一方式可以让你的代码干净、可读并且健壮。

Introduction

Feature
[TODO] 细化

  • Synchronous inspection
  • Concurrency coordination
  • Promisification on steroids
  • Debuggability and error handling
  • Resource management
  • Cancellation and timeouts
  • Scoped prototypes
  • Promise monitoring
  • Async/Await

Reference

2.6 AVA - 面向未来的测试运行器

Introduction
AVA时Mocha的替代品
虽然 JavaScript 是单线程,但在 Node.js 里由于其异步的特性使得 IO 可以并行。AVA 利用这个优点让你的测试可以并发执行,这对于 IO 繁重的测试特别有用。另外,测试文件可以在不同的进程里并行运行,让每一个测试文件可以获得更好的性能和独立的环境。在 Pageres 项目中从 Mocha切换 到 AVA 让测试时间从 31 秒下降到 11 秒。测试并发执行强制你写原子测试,意味着测试不需要依赖全局状态或者其他测试的状态,这是一件非常好的事情。
Feature

  • 轻量和高效
  • 简单的测试语法
  • 并发运行测试
  • 强制编写原子测试
  • 没有隐藏的全局变量
  • 为每个测试文件隔离环境
  • 新语法支持
    用 ES2015 编写测试,支持 Promise,Generator,Async,Observable
  • 强化断言信息
  • 可选的 TAP 输出显示
  • 简明的堆栈跟踪

@Reference

2.7 VSCode - Debug工具

替代文字替代文字
@Introduction

Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, Mac and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages (such as C++, C#, Python, PHP) and runtimes. Begin your journey with VS Code with these introductory videos.

轻量级的代码编辑器,跨平台的桌面软件。具有丰富的插件支持和开发生态,支持多种语言和运行环境。

@Feature

  • 跨平台 vsc是一个比较潮比较新的编辑器(跨平台Mac OS X、Windows和 Linux )
  • 功能丰富
    vsc功能和textmate、sublime、notepad++,ultraedit等比较,毫不逊色
  • Nodejs 调试方便
    vsc尤其是在nodejs(调试)和typescript、go上支持尤其好
    vsc提供了自定义 Debugger Adapter 和 VSCode Debug Protocol 从而实现自己的调试器

@Reference

构建工具

[TODO]

数据库

MongoDB - NoSQL文档型数据库

<应用场景 分析 MySQL 与 MongoDB>为啥采用MongoDB
文档管理

Redis 内存数据库 - Redis

用途:用于Session管理

版本管理

工具 Git
代码仓库 Github

  • 《Git工作流-流程规范》[TODO]

运行环境

开发IDE - [TODO NodeJS和前端所适合的开发工具]
OS - Ubuntu [TODO 版本 目前稳定运行的Ubuntu版本]

<Template>

Name

@Introduction

@Feature

@Reference

相关文章

网友评论

    本文标题:Node 技术栈

    本文链接:https://www.haomeiwen.com/subject/kwalyttx.html