Skip to content

Commit 18f292c

Browse files
author
xiaolongXL
committed
update document
1 parent 434dddc commit 18f292c

2 files changed

Lines changed: 9 additions & 57 deletions

File tree

doc/day1_express.md

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -142,30 +142,6 @@ generator是express命令工具集,首先确保已经安装node和npm,先在
142142

143143
TODO:by kezhi
144144

145-
```
146-
Usage: express [options] [dir]
147-
148-
Options:
149-
150-
-h, --help output usage information //
151-
-V, --version output the version number
152-
-e, --ejs add ejs engine support (defaults to jade)
153-
--hbs add handlebars engine support
154-
-H, --hogan add hogan.js engine support
155-
-c, --css <engine> add stylesheet <engine> support (less|stylus|compass) (defaults to plain css)
156-
-f, --force force on non-empty directory
157-
158-
express --help //查看帮助
159-
express --version //查看版本
160-
express --ejs //添加模板引擎,默认为jade
161-
express --hbs //添加handlebars模板
162-
express --hogan //添加hogan.js模板
163-
express --css //添加css引擎,默认为plain css
164-
165-
166-
```
167-
168-
169145
#### 安装依赖
170146

171147
打开package.json,可以看到依赖的模块,执行命令来下载依赖的模块:
@@ -306,12 +282,6 @@ app.js里
306282

307283
在静态页面处理请求参数,是通过连接地址把参数传递过去,通过前端jacascript取出做处理(by kezhi)。
308284

309-
```
310-
$.get('http://localhost:3000/get',function(data){
311-
$('.get-name').val(data.data.name)
312-
})
313-
```
314-
315285

316286
#### 理解express.static
317287

@@ -348,23 +318,6 @@ express.static不仅可以托管静态文件,并且提供接口可以拦截到
348318

349319
安装supervisor(by kezhi)
350320

351-
由于supervisor是方便于开发的,所以我们将添加开发阶段的依赖:
352-
353-
```
354-
npm install --save-dev supervisor
355-
```
356-
357-
安装完成后package.json文件中将会多出 `supervisor`的依赖
358-
```
359-
"devDependencies": {
360-
"supervisor": "^0.6.0"
361-
}
362-
```
363-
修改package.json中的scripts:
364-
365-
```
366-
"start": "node_modules/.bin/supervisor ./bin/www"
367-
```
368321

369322
### 路由定制方式
370323
路由定制方式有2种
@@ -554,17 +507,7 @@ query处理get请求参数,整理成json各式:
554507
router.get('/www:soso', function(req, res) {
555508
res.send(req.query);
556509
});
557-
558-
param取路由中的参数:
559-
560-
```
561-
router.post('/post/:id', function(req, res) {
562-
res.status(200).json({
563-
res.send(req.param('id'));
564-
})
565-
})
566510

567-
```
568511
### response返回
569512

570513
- text
@@ -582,10 +525,19 @@ router.post('/post/:id', function(req, res) {
582525

583526
试着说明package.json的众多方面
584527

528+
package.json是描述项目文件,描述项目所依赖的模块,当我们把一个项目发布到npm时,其实不用把我们所依赖的模块一起发不上去,只需要把依赖的模块名称填写到package.json里面,当别人npm install的时候,npm会去识别package.json中所依赖的模块名称,然后下载下来:
529+
585530
- `npm install --save` vs `npm install --save-dev`
586531
- `npm start` vs `npm test` (scripts自定义)
587532
- 如何写一个npm,以及发布
588533

534+
当我们通过npm安装某一模块时,运用`npm install --save`或者`npm install --save-dev`,npm则会把我们的项目依赖信息写入package.json中。
535+
536+
`npm install --save``npm install --save-dev`的区别:
537+
538+
devDependencies下列出的模块,是我们开发时用的,比如grunt-contrib-uglify,我们用它混淆js文件,它们不会被部署到生产环境。dependencies下的模块,则是我们生产环境中需要的依赖。
539+
540+
589541

590542
## 阅读文档
591543

doc/images/expressimg2.jpg

-393 KB
Loading

0 commit comments

Comments
 (0)