Node 技术栈

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

整体架构

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

  • 文档编写语言 MarkDown
    Markdown 语法说明 (体中文版)
    http://www.appinn.com/markdown/

前端

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

  • jQuery | Home
    https://jquery.com/

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

  • NodeJS | Home
    https://nodejs.org/en/

  • modern-nodejs - 狼叔
    https://i5ting.github.io/modern-nodejs/#101
    Nodejs的新的特性

  • [CNode-i5ting]Node.js最新Web技术栈(2016年4月)
    https://cnodejs.org/topic/56fdf66ec5f5b4a959e91771
    NodeJS的技术栈主要参考狼叔的这个方案,除了模板引擎外。

  • 从零开始nodejs系列文章 - 张丹
    http://blog.fens.me/series-nodejs/
    张丹老师 比较详细的整理了NodeJS的学习教程
    (部分内容可能已过时)

  • IT博客汇-Node
    http://wrox.cn/tag/node/
    比较高质量的前端博客汇总,就是从这里知道了神器的狼叔。

  • Node.js 6.0 Supports 93% of ES2015
    https://www.infoq.com/news/2016/04/nodejs-6
    总结了Nodejs 6 的一些新的特性,选择Node6的分析,主要参考此文章

  • Java项目如何与Node.js共存?
    https://github.com/i5ting/nodejs-arch-for-java
    在架构方面,Nodejs比较擅长I/O操作,弱项可以与其他语言互补。该文章综合对比了Node与Java Web的架构,与目前的几种共存方案。

2.2 Koajs2 - Node.js Web框架

Node 技术栈_第1张图片
Koajs2

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)需要[email protected]配合使用。
    避免繁琐函数回调,提高错误处理效率

@Reference

  • Koa HomePage
    http://koa.rednode.cn/

  • [Github - i5ting]StuQ分享专题《深入浅出js(Node.js)异步流程控制》完整版
    https://github.com/i5ting/asynchronous-flow-control/blob/master/31.md

  • Node.js Async Tutorial
    http://justinklemm.com/node-js-async-tutorial/

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

  • Mongoose | Home
    http://mongoosejs.com/

  • getting-started-with-mongoose
    http://blog.modulus.io/getting-started-with-mongoose

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

  • Features | Bluebird
    http://bluebirdjs.com/docs/features.html

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

  • [Github-AVA] AVA | Home
    https://github.com/avajs/ava

  • [CNode-i5ting]AVA实践:面向未来的测试运行器
    https://cnodejs.org/topic/57464cd8da0dea851e308101
    我选择AVA的测试框架,主要时因为它支持Koa2的 async/wait的流程控制。这文档是狼叔对上面的英文版文档的翻译。

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

  • VSCode Document For Linux
    https://code.visualstudio.com/docs/?dv=linux64_deb

  • [Github-i5ting]Visual Studio Code Guide[Simple Chinese][简体中文]
    http://i5ting.github.io/vsc/
    狼叔写的VSCode的教程,膜拜

构建工具

[TODO]

数据库

MongoDB - NoSQL文档型数据库

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

Redis 内存数据库 - Redis

用途:用于Session管理

版本管理

工具 Git
代码仓库 Github

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

运行环境

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