Skip to content

Commit

Permalink
docs: edit docs/node
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanyf committed Oct 31, 2016
1 parent 994ea3b commit 165a15c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
6 changes: 3 additions & 3 deletions demos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
- [ReCharts](#recharts)
- [MobX](#mobx)
- [Redux](#redux)
- [Simple App]()
- [REST API]()
- [Simple App](#simple-app)
- [REST API](#rest-api)
- [Express](#express)
- [ESLint](#eslint)
- [Mocha](#mocha)
- [Travis CI]()
- [Travis CI](#travis-ci)

## Backbone

Expand Down
Binary file added docs/images/redux-architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 43 additions & 9 deletions docs/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

Node 是服务器的 JavaScript 运行环境,提供 API 与操作系统互动。

用途
主要用途

- 开发前端应用
- 搭建服务
- 快速搭建服务

---

Expand All @@ -27,15 +27,15 @@ $ npm -v

## 课堂练习:Node 的简单应用

进入`demos/simple-app-demo`目录,参考《操作指南》,自己动手在 Node 里面,编写并编译一个前端脚本。
进入`demos/simple-app-demo`目录,参考[《操作指南》](../demos/README.md#simple-app),自己动手在 Node 里面,编写并编译一个前端脚本。

---

## Node 开发前端脚本的好处

1. 模块机制
1. 版本管理
1. 持续集成的标准软件开发流程
1. 持续集成的标准开发流程

---

Expand Down Expand Up @@ -92,7 +92,7 @@ DELETE /v1/stores/1234

## 课堂练习:REST API

打开`demos/rest-api-demo`,按照《操作指南》,熟悉 REST API 的基本用法。
打开`demos/rest-api-demo`,按照[《操作指南》](../demos/README.md#rest-api),熟悉 REST API 的基本用法。

---

Expand All @@ -106,10 +106,44 @@ Express 是最常用的 Node 框架,用来搭建 Web 应用。

## 课堂练习:Express 搭建 Web 应用

进入`demos/express-demo`目录,按照《操作指南》,学习使用 Express 搭建 Web 应用。
进入`demos/express-demo`目录,按照[《操作指南》](demos/README.md#express),学习使用 Express 搭建 Web 应用。

学习重点
---

定义一个 Web 应用实例,并且启动它。

```javascript
var express = require('express');
var app = express();

var port = process.env.PORT || 8080;

app.listen(port);
console.log('Magic happens on port ' + port);
```

---

定义一个路由

- 路由设置
- 中间件
```javascript
var router = express.Router();

router.get('/', function(req, res) {
res.send('<h1>Hello World</h1>');
});

app.use('/home', router);
```

---

中间件:对 HTTP 请求进行加工。

```javascript
router.use(function(req, res, next) {
console.log('Thers is a requesting.');
next();
});
```

2 changes: 1 addition & 1 deletion docs/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Redux 的核心概念
- 用户在 UI 上发出`action`
- `reducer`函数接收`action`,然后根据当前的`state`,计算出新的`state`

![](./images/redux.svg)
![](./images/redux-architecture.png)

---

Expand Down

0 comments on commit 165a15c

Please sign in to comment.